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 RandStr =
"xacvgeze";
44 TEST(TestBubble, BubbleSorts)
48 Container vector(ArrayRand);
49 Bubble<IT>(vector.begin(), vector.end());
52 for (
auto it = vector.begin(); it < vector.end() - 1; ++it)
53 EXPECT_LE(*it, *(it + 1));
58 Container vector(ArraySort);
59 Bubble<IT>(vector.begin(), vector.end());
62 for (
auto it = vector.begin(); it < vector.end() - 1; ++it)
63 EXPECT_LE(*it, *(it + 1));
68 Container vector(ArrayRand);
69 Bubble<IT>(vector.end(), vector.begin());
72 for (
auto it = vector.begin(); it < vector.end(); ++it, ++i)
73 EXPECT_EQ(ArrayRand[i], *it);
79 Bubble<IT>(emptyArray.begin(), emptyArray.end());
84 Container uniqueValueArray(1, 511);
85 Bubble<IT>(uniqueValueArray.begin(), uniqueValueArray.end());
86 EXPECT_EQ(511, uniqueValueArray[0]);
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));
99 TEST(TestBubble, BubbleGreaterComparator)
103 Container vector(ArrayRand);
104 Bubble<IT, GE_Comparator>(vector.begin(), vector.end());
107 for (
auto it = vector.begin(); it < vector.end() - 1; ++it)
108 EXPECT_GE(*it, *(it + 1));
113 Container vector(ArraySort);
114 Bubble<IT, GE_Comparator>(vector.begin(), vector.end());
117 for (
auto it = vector.begin(); it < vector.end() - 1; ++it)
118 EXPECT_GE(*it, *(it + 1));
123 std::string stringToSort = RandStr;
124 Bubble<std::string::iterator, std::greater<char>>(stringToSort.begin(), stringToSort.end());
127 for (
auto it = stringToSort.begin(); it < stringToSort.end() - 1; ++it)
128 EXPECT_GE(*it, *(it + 1));
TEST(TestBubble, BubbleSorts)