TestComb.cxx File Reference
#include <gtest/gtest.h>
#include <comb.hxx>
#include <functional>
#include <vector>
#include <string>
Include dependency graph for TestComb.cxx:

Go to the source code of this file.

Functions

 TEST (TestComb, CombSorts)
 
 TEST (TestComb, CombGreaterComparator)
 

Function Documentation

TEST ( TestComb  ,
CombSorts   
)

Definition at line 44 of file TestComb.cxx.

45 {
46  // Normal Run
47  {
48  Container randomdArray(ArrayRand);
49  Comb<IT>(randomdArray.begin(), randomdArray.end());
50 
51  // All elements are sorted
52  for (auto it = randomdArray.begin(); it < randomdArray.end() - 1; ++it)
53  EXPECT_LE(*it, *(it + 1));
54  }
55 
56  // Already Sorted Array - Array should not be affected
57  {
58  Container vector(ArraySort);
59  Comb<IT>(vector.begin(), vector.end());
60 
61  // All elements are still sorted
62  for (auto it = vector.begin(); it < vector.end() - 1; ++it)
63  EXPECT_LE(*it, *(it + 1));
64  }
65 
66  // Inverse iterator order - Array should not be affected
67  {
68  Container randomdArray(ArrayRand);
69  Comb<IT>(randomdArray.end(), randomdArray.begin());
70 
71  int i = 0;
72  for (auto it = randomdArray.begin(); it < randomdArray.end(); ++it, ++i)
73  EXPECT_EQ(ArrayRand[i], *it);
74  }
75 
76  // No error unitialized array
77  {
78  Container emptyArray;
79  Comb<IT>(emptyArray.begin(), emptyArray.end());
80  }
81 
82  // Unique value array - Array should not be affected
83  {
84  Container uniqueValueArray(1, 511);
85  Comb<IT>(uniqueValueArray.begin(), uniqueValueArray.end());
86  EXPECT_EQ(511, uniqueValueArray[0]);
87  }
88 
89  // String - String should be sorted as an array
90  {
91  std::string stringToSort = RandomStr;
92  Comb<std::string::iterator, std::less<char>>(stringToSort.begin(), stringToSort.end());
93  for (auto it = stringToSort.begin(); it < stringToSort.end() - 1; ++it)
94  EXPECT_LE(*it, *(it + 1));
95  }
96 }
TEST ( TestComb  ,
CombGreaterComparator   
)

Definition at line 99 of file TestComb.cxx.

100 {
101  // Normal Run - Elements should be sorted in inverse order
102  {
103  Container randomdArray(ArrayRand);
104  Comb<IT, GE_Comparator>(randomdArray.begin(), randomdArray.end());
105 
106  // All elements are sorted in inverse order
107  for (auto it = randomdArray.begin(); it < randomdArray.end() - 1; ++it)
108  EXPECT_GE(*it, *(it + 1));
109  }
110 
111  // Already sorted Array in inverse order - Array should not be affected
112  {
113  Container invArraySort(ArraySort);
114  Comb<IT, GE_Comparator>(invArraySort.begin(), invArraySort.end());
115 
116  // All elements are still sorted in inverse order
117  for (auto it = invArraySort.begin(); it < invArraySort.end() - 1; ++it)
118  EXPECT_GE(*it, *(it + 1));
119  }
120 
121  // String - String should be sorted in inverse order
122  {
123  std::string stringToSort = RandomStr;
124  Comb<std::string::iterator, std::greater<char>>(stringToSort.begin(), stringToSort.end());
125 
126  // All elements are sorted in inverse order
127  for (auto it = stringToSort.begin(); it < stringToSort.end() - 1; ++it)
128  EXPECT_GE(*it, *(it + 1));
129  }
130 }