20 #include <gtest/gtest.h> 33 typedef std::vector<int> Container;
34 typedef Container::iterator IT;
35 typedef std::greater<IT::value_type> GE_Comparator;
37 const Container ArraySort = {-3, -2, 0, 2, 8, 15, 36, 212, 366};
38 const Container ArrayRand = {4, 3, 5, 2, -18, 3, 2, 3, 4, 5, -5};
39 const std::string StrRand =
"xacvgeze";
44 TEST(TestQuick, QuickSorts)
48 Container randomdArray(ArrayRand);
49 QuickSort<IT>(randomdArray.begin(), randomdArray.end());
52 for (
auto it = randomdArray.begin(); it < randomdArray.end() - 1; ++it)
53 EXPECT_LE(*it, *(it + 1));
58 Container sortedArray(ArraySort);
59 QuickSort<IT>(sortedArray.begin(), sortedArray.end());
62 for (
auto it = sortedArray.begin(); it < sortedArray.end() - 1; ++it)
63 EXPECT_LE(*it, *(it + 1));
68 Container randomdArray(ArrayRand);
69 QuickSort<IT>(randomdArray.end(), randomdArray.begin());
72 for (
auto it = randomdArray.begin(); it < randomdArray.end(); ++it, ++i)
73 EXPECT_EQ(ArrayRand[i], *it);
79 QuickSort<IT>(emptyArray.begin(), emptyArray.end());
84 Container uniqueValueArray(1, 511);
85 QuickSort<IT>(uniqueValueArray.begin(), uniqueValueArray.end());
86 EXPECT_EQ(511, uniqueValueArray[0]);
91 std::string stringToSort = StrRand;
92 QuickSort<std::string::iterator, std::less_equal<char>>(stringToSort.begin(), stringToSort.end());
93 for (
auto it = stringToSort.begin(); it < stringToSort.end() - 1; ++it)
94 EXPECT_LE(*it, *(it + 1));
99 TEST(TestQuick, QuickSortGreaterComparator)
103 Container randomdArray(ArrayRand);
104 QuickSort<IT, GE_Comparator>(randomdArray.begin(), randomdArray.end());
107 for (
auto it = randomdArray.begin(); it < randomdArray.end() - 1; ++it)
108 EXPECT_GE(*it, *(it + 1));
113 Container invSortedArray(ArraySort);
114 QuickSort<IT, GE_Comparator>(invSortedArray.begin(), invSortedArray.end());
117 for (
auto it = invSortedArray.begin(); it < invSortedArray.end() - 1; ++it)
118 EXPECT_GE(*it, *(it + 1));
123 std::string stringToSort = StrRand;
124 QuickSort<std::string::iterator, std::greater_equal<char>>(stringToSort.begin(), stringToSort.end());
127 for (
auto it = stringToSort.begin(); it < stringToSort.end() - 1; ++it)
128 EXPECT_GE(*it, *(it + 1));
TEST(TestQuick, QuickSorts)