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

Go to the source code of this file.

Functions

 TEST (TestPartition, Partitions)
 
 TEST (TestPartition, PartitionString)
 
 TEST (TestPartition, PartitionBoudaryPivots)
 
 TEST (TestPartition, PartitionGreaterComparator)
 

Function Documentation

TEST ( TestPartition  ,
Partitions   
)

Definition at line 71 of file TestPartition.cxx.

72 {
73  // Normal Run - Random Array
74  {
75  Container vector(ArrayRand);
76  auto pivot = vector.begin() + 5;
77  auto pivotVal = *pivot;
78 
79  // Run partition - Should result in: max[begin, pivot[ <= pivot <= min]pivot, end]
80  auto newPivot = Partition<IT>(vector.begin(), pivot, vector.end());
81  CheckPartition<IT>(vector.begin(), vector.end(), newPivot, pivotVal);
82  }
83 
84  // Already sortedArray - Array should not be affected
85  {
86  Container vector(ArraySort);
87  auto pivot = vector.begin() + 5;
88 
89  Partition<IT>(vector.begin(), pivot, vector.end());
90 
91  int i = 0;
92  for (auto it = vector.begin(); it < vector.end(); ++it, ++i)
93  EXPECT_EQ(ArraySort[i], *it);
94  }
95 
96  // Begin and End inversed - Array should not be affected
97  {
98  Container vector(ArrayRand);
99  auto pivot = vector.begin() + 5;
100 
101  Partition<IT>(vector.end(), pivot, vector.begin());
102 
103  int i = 0;
104  for (auto it = vector.begin(); it < vector.end(); ++it, ++i)
105  EXPECT_EQ(ArrayRand[i], *it);
106  }
107 }
TEST ( TestPartition  ,
PartitionString   
)

Definition at line 110 of file TestPartition.cxx.

111 {
112  std::string str = StrRand;
113  auto pivot = str.begin() + 5;
114  auto pivotVal = *pivot;
115 
116  auto newPivot = Partition<std::string::iterator>(str.begin(), pivot, str.end());
117  CheckPartition<std::string::iterator>(str.begin(), str.end(), newPivot, pivotVal);
118 }
TEST ( TestPartition  ,
PartitionBoudaryPivots   
)

Definition at line 121 of file TestPartition.cxx.

122 {
123  // Pivot choose as begin
124  {
125  Container vector(ArrayRand);
126  auto pivot = vector.begin();
127  const int pivotVal = *pivot;
128 
129  // Run partition
130  auto newPivot = Partition<IT>(vector.begin(), pivot, vector.end());
131  CheckPartition<IT>(vector.begin(), vector.end(), newPivot, pivotVal);
132 
133  }
134 
135  // Pivot choose as last element
136  {
137  Container vector(ArrayRand);
138  auto pivot = vector.end() - 1;
139  const int pivotVal = *pivot;
140 
141  // Run partition
142  auto newPivot = Partition<IT>(vector.begin(), pivot, vector.end());
143  CheckPartition<IT>(vector.begin(), vector.end(), newPivot, pivotVal);
144  }
145 
146  // Pivot choose as end - cannot process
147  {
148  Container vector(ArrayRand);
149  auto pivot = vector.end();
150 
151  // Run partition
152  Partition<IT>(vector.begin(), pivot, vector.end());
153 
154  int i = 0;
155  for (auto it = vector.begin(); it < vector.end(); ++it, ++i)
156  EXPECT_EQ(ArrayRand[i], *it);
157  }
158 }
TEST ( TestPartition  ,
PartitionGreaterComparator   
)

Definition at line 161 of file TestPartition.cxx.

162 {
163  // Normal Run - Should result in: min[begin, pivot[ >= pivot >= max]pivot, end]
164  {
165  Container vector(ArrayRand);
166  auto pivot = vector.begin() + 5;
167  const auto pivotVal = *pivot;
168 
169  // Run partition
170  auto newPivot = Partition<IT, GE_Compare>(vector.begin(), pivot, vector.end());
171  CheckPartition<IT>(vector.begin(), vector.end(), newPivot, pivotVal, false);
172  }
173 
174  // Already InverseSortedArray - Array should not be affected
175  {
176  Container invSortedArray(ArrayInvSort);
177  auto pivot = invSortedArray.begin() + 5;
178 
179  Partition<IT, GE_Compare>(invSortedArray.begin(), pivot, invSortedArray.end());
180 
181  int i = 0;
182  for (auto it = invSortedArray.begin(); it < invSortedArray.end(); ++it, ++i)
183  EXPECT_EQ(invSortedArray[i], *it);
184  }
185 
186  // String collection - Should result in: min[begin, pivot[ >= pivot >= max]pivot, end]
187  {
188  std::string str = StrRand;
189  auto pivot = str.begin() + 5;
190  const auto pivotVal = *pivot;
191 
192  // Run partition
193  auto newPivot =
194  Partition<std::string::iterator, std::greater_equal<char>>(str.begin(), pivot, str.end());
195  CheckPartition<std::string::iterator>(str.begin(), str.end(), newPivot, pivotVal, false);
196  }
197 }