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 (TestSort, BubbleSorts)
 
 TEST (TestSort, BubbleGreaterComparator)
 

Function Documentation

TEST ( TestSort  ,
BubbleSorts   
)

Definition at line 47 of file TestBubble.cxx.

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

Definition at line 102 of file TestBubble.cxx.

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