TestMaxMElements.cxx File Reference
#include <gtest/gtest.h>
#include <max_m_elements.hxx>
Include dependency graph for TestMaxMElements.cxx:

Go to the source code of this file.

Functions

 TEST (TestSearch, MaxMElements)
 
 TEST (TestSearch, MaxNElementsLowestValues)
 

Function Documentation

TEST ( TestSearch  ,
MaxMElements   
)

Definition at line 38 of file TestMaxMElements.cxx.

39 {
40  // Should return the max value [5] for a unique element search
41  {
42  Container kRandomElements(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
43  Container kMaxElements = MaxMElements<Container, IT>(kRandomElements.begin(), kRandomElements.end(), 1);
44  EXPECT_EQ(5, kMaxElements[0]);
45  }
46 
47  // Should return [5,5,4]
48  {
49  Container kRandomElements (RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
50  Container kMaxElements =MaxMElements<Container, IT>(kRandomElements.begin(), kRandomElements.end(), 3);
51  EXPECT_EQ(5, kMaxElements[0]);
52  EXPECT_EQ(5, kMaxElements[1]);
53  EXPECT_EQ(4, kMaxElements[2]);
54  }
55 
56  // Should return the last elements on sorted vector
57  {
58  Container kSortedArray(SortedArrayInt, SortedArrayInt + sizeof(SortedArrayInt) / sizeof(int));
59  Container kMaxElements = MaxMElements<Container, IT>(kSortedArray.begin(), kSortedArray.end(), 4);
60  EXPECT_EQ(366, kMaxElements[0]);
61  EXPECT_EQ(212, kMaxElements[1]);
62  EXPECT_EQ(36, kMaxElements[2]);
63  EXPECT_EQ(15, kMaxElements[3]);
64  }
65 
66  // Should return empty vector on insufficient vector
67  {
68  Container uniqueEl = Container(1, 2);
69  Container kMaxElements = MaxMElements<Container, IT>(uniqueEl.begin(), uniqueEl.end(), 2);
70  EXPECT_EQ(0, static_cast<int>(kMaxElements.size()));
71  }
72 
73  // Should return empty vector when looking for less than 1 elements
74  {
75  Container uniqueEl = Container(1, 2);
76  Container kMaxElements = MaxMElements<Container, IT>(uniqueEl.begin(), uniqueEl.end(), 0);
77  EXPECT_EQ(0, static_cast<int>(kMaxElements.size()));
78  }
79 }
TEST ( TestSearch  ,
MaxNElementsLowestValues   
)

Definition at line 82 of file TestMaxMElements.cxx.

83 {
84  // Should return the min value [-18] for a unique element search
85  {
86  Container kRandomElements(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
87  Container kMaxElements =
88  MaxMElements<Container, IT, std::less_equal<int>>
89  (kRandomElements.begin(), kRandomElements.end(), 1);
90  EXPECT_EQ(-18, kMaxElements[0]);
91  }
92 
93  // Should return [5,5,4]
94  {
95  Container kRandomElements(RandomArrayInt, RandomArrayInt + sizeof(RandomArrayInt) / sizeof(int));
96  Container kMaxElements = MaxMElements<Container, IT, std::less_equal<int>>
97  (kRandomElements.begin(), kRandomElements.end(), 3);
98  EXPECT_EQ(-18, kMaxElements[0]);
99  EXPECT_EQ(-5, kMaxElements[1]);
100  EXPECT_EQ(2, kMaxElements[2]);
101  }
102 
103  // Should return the first elements on sorted vector
104  {
105  Container kSortedArray(SortedArrayInt, SortedArrayInt + sizeof(SortedArrayInt) / sizeof(int));
106  Container kMaxElements = MaxMElements<Container, IT, std::less_equal<int>>
107  (kSortedArray.begin(), kSortedArray.end(), 4);
108  EXPECT_EQ(-3, kMaxElements[0]);
109  EXPECT_EQ(-2, kMaxElements[1]);
110  EXPECT_EQ(0, kMaxElements[2]);
111  EXPECT_EQ(2, kMaxElements[3]);
112  }
113 }