TestKthMaxElement.cxx File Reference
#include <gtest/gtest.h>
#include <kth_max_element.hxx>
#include <functional>
Include dependency graph for TestKthMaxElement.cxx:

Go to the source code of this file.

Functions

 TEST (TestSearch, MaxKthElement)
 
 TEST (TestSearch, MinKthElement)
 

Function Documentation

TEST ( TestSearch  ,
MaxKthElement   
)

Definition at line 41 of file TestKthMaxElement.cxx.

42 {
43  {
44  // Basic run on random array - Should return 4
45  Container krandomdArray(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
46  EXPECT_EQ(4, *MaxKthElement<IT>(krandomdArray.begin(), krandomdArray.end(), 7));
47  }
48 
49  Container ksortedArray(SortedArrayInt, SortedArrayInt + sizeof(SortedArrayInt) / sizeof(int));
50 
51  // Basic run on sorted array with unique element - Should the kth element
52  EXPECT_EQ(ksortedArray.begin() + 4, MaxKthElement<IT>(ksortedArray.begin(), ksortedArray.end(), 4));
53 
54  // Empty sequence - Should return end on empty sequence
55  EXPECT_EQ(ksortedArray.begin(), MaxKthElement<IT>(ksortedArray.begin(), ksortedArray.begin(), 0));
56 
57  // Unique element sequence - Should return the unique element
58  EXPECT_EQ(ksortedArray.begin(), MaxKthElement<IT>(ksortedArray.begin(), ksortedArray.begin() + 1, 0));
59 
60  // Negative index - Should return end for out of scope search (k = 0)
61  EXPECT_EQ(ksortedArray.begin(), MaxKthElement<IT>(ksortedArray.begin(), ksortedArray.end(), 0));
62 
63  // k bigger than the size of the sequence - Should return end for out of scope search
64  EXPECT_EQ(ksortedArray.end(), MaxKthElement<IT>(ksortedArray.begin(), ksortedArray.end(), 100));
65 
66  // String
67  {
68  std::string randomStr = RandomStr;
69  const char secondSmallestLetter = *MaxKthElement
70  <std::string::iterator, std::less_equal<char>>(randomStr.begin(), randomStr.end(), 1);
71  EXPECT_EQ('c', secondSmallestLetter);
72  }
73 }
IT MaxKthElement(const IT &begin, const IT &end, unsigned int k)
TEST ( TestSearch  ,
MinKthElement   
)

Definition at line 76 of file TestKthMaxElement.cxx.

77 {
78  // Basic run on random array - Should return 5 (second biggest value)
79  Container krandomdArray(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
80  IT::value_type value = *MaxKthElement<IT, GR_Compare>(krandomdArray.begin(), krandomdArray.end(), 1);
81  EXPECT_EQ(5, value);
82 }