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

Go to the source code of this file.

Functions

 TEST (TestSearch, KthOrderStatistic)
 
 TEST (TestSearch, MinKthElement)
 

Function Documentation

TEST ( TestSearch  ,
KthOrderStatistic   
)

Definition at line 41 of file TestKthOrderStatistic.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, *KthOrderStatistic<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, KthOrderStatistic<IT>(ksortedArray.begin(), ksortedArray.end(), 4));
53 
54  // Empty sequence - Should return end on empty sequence
55  EXPECT_EQ(ksortedArray.begin(), KthOrderStatistic<IT>(ksortedArray.begin(), ksortedArray.begin(), 0));
56 
57  // Unique element sequence - Should return the unique element
58  EXPECT_EQ(ksortedArray.begin(), KthOrderStatistic<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(), KthOrderStatistic<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(), KthOrderStatistic<IT>(ksortedArray.begin(), ksortedArray.end(), 100));
65 
66  // String
67  {
68  std::string randomStr = RandomStr;
69  const char secondSmallestLetter = *KthOrderStatistic
70  <std::string::iterator, std::less_equal<char>>(randomStr.begin(), randomStr.end(), 1);
71  EXPECT_EQ('c', secondSmallestLetter);
72  }
73 }
IT KthOrderStatistic(const IT &begin, const IT &end, unsigned int k)
TEST ( TestSearch  ,
MinKthElement   
)

Definition at line 76 of file TestKthOrderStatistic.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 = *KthOrderStatistic<IT, GR_Compare>(krandomdArray.begin(), krandomdArray.end(), 1);
81  EXPECT_EQ(5, value);
82 }