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

Go to the source code of this file.

Functions

 TEST (TestCocktail, CocktailSorts)
 
 TEST (TestCocktail, CocktailGreaterComparator)
 

Function Documentation

TEST ( TestCocktail  ,
CocktailSorts   
)

Definition at line 44 of file TestCocktail.cxx.

45 {
46  // Normal Run
47  {
48  Container randomdArray(ArrayRand);
49  Cocktail<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 ArraySort - Array should not be affected
57  {
58  Container ArraySort(ArraySort);
59  Cocktail<IT>(ArraySort.begin(), ArraySort.end());
60 
61  // All elements are still sorted
62  for (auto it = ArraySort.begin(); it < ArraySort.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  Cocktail<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  Cocktail<IT>(emptyArray.begin(), emptyArray.end());
80  }
81 
82  // Unique value array - Array should not be affected
83  {
84  Container uniqueValueArray(1, 511);
85  Cocktail<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 = StrRand;
92  Cocktail<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 ( TestCocktail  ,
CocktailGreaterComparator   
)

Definition at line 99 of file TestCocktail.cxx.

100 {
101  // Normal Run - Elements should be sorted in inverse order
102  {
103  Container randomdArray(ArrayRand);
104  Cocktail<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  Cocktail<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 = StrRand;
124  Cocktail<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 }