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

Go to the source code of this file.

Functions

 TEST (TestBubble, BubbleSorts)
 
 TEST (TestBubble, BubbleGreaterComparator)
 

Function Documentation

TEST ( TestBubble  ,
BubbleSorts   
)

Definition at line 44 of file TestBubble.cxx.

45 {
46  // Normal Run
47  {
48  Container vector(ArrayRand);
49  Bubble<IT>(vector.begin(), vector.end());
50 
51  // All elements are sorted
52  for (auto it = vector.begin(); it < vector.end() - 1; ++it)
53  EXPECT_LE(*it, *(it + 1));
54  }
55 
56  // Already ArraySort - Array should not be affected
57  {
58  Container vector(ArraySort);
59  Bubble<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 vector(ArrayRand);
69  Bubble<IT>(vector.end(), vector.begin());
70 
71  int i = 0;
72  for (auto it = vector.begin(); it < vector.end(); ++it, ++i)
73  EXPECT_EQ(ArrayRand[i], *it);
74  }
75 
76  // No error unitialized array
77  {
78  Container emptyArray;
79  Bubble<IT>(emptyArray.begin(), emptyArray.end());
80  }
81 
82  // Unique value array - Array should not be affected
83  {
84  Container uniqueValueArray(1, 511);
85  Bubble<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 = RandStr;
92  Bubble<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 ( TestBubble  ,
BubbleGreaterComparator   
)

Definition at line 99 of file TestBubble.cxx.

100 {
101  // Normal Run - Elements should be sorted in inverse order
102  {
103  Container vector(ArrayRand);
104  Bubble<IT, GE_Comparator>(vector.begin(), vector.end());
105 
106  // All elements are sorted in inverse order
107  for (auto it = vector.begin(); it < vector.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 vector(ArraySort);
114  Bubble<IT, GE_Comparator>(vector.begin(), vector.end());
115 
116  // All elements are still sorted in inverse order
117  for (auto it = vector.begin(); it < vector.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 = RandStr;
124  Bubble<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 }