1 #include "human_sort.hpp" 2 3 #include <set> 4 #include <string> 5 6 #include <gmock/gmock.h> 7 #include <gtest/gtest.h> 8 9 namespace 10 { 11 12 using ::testing::ElementsAreArray; 13 14 TEST(AlphaNum, NumberTests) 15 { 16 // testcases for the algorithm 17 EXPECT_EQ(alphanumComp("", ""), 0); 18 EXPECT_LT(alphanumComp("", "a"), 0); 19 EXPECT_GT(alphanumComp("a", ""), 0); 20 EXPECT_EQ(alphanumComp("a", "a"), 0); 21 EXPECT_LT(alphanumComp("", "9"), 0); 22 EXPECT_GT(alphanumComp("9", ""), 0); 23 EXPECT_EQ(alphanumComp("1", "1"), 0); 24 EXPECT_LT(alphanumComp("1", "2"), 0); 25 EXPECT_GT(alphanumComp("3", "2"), 0); 26 EXPECT_EQ(alphanumComp("a1", "a1"), 0); 27 EXPECT_LT(alphanumComp("a1", "a2"), 0); 28 EXPECT_GT(alphanumComp("a2", "a1"), 0); 29 EXPECT_LT(alphanumComp("a1a2", "a1a3"), 0); 30 EXPECT_GT(alphanumComp("a1a2", "a1a0"), 0); 31 EXPECT_GT(alphanumComp("134", "122"), 0); 32 EXPECT_EQ(alphanumComp("12a3", "12a3"), 0); 33 EXPECT_GT(alphanumComp("12a1", "12a0"), 0); 34 EXPECT_LT(alphanumComp("12a1", "12a2"), 0); 35 EXPECT_LT(alphanumComp("a", "aa"), 0); 36 EXPECT_GT(alphanumComp("aaa", "aa"), 0); 37 EXPECT_EQ(alphanumComp("Alpha 2", "Alpha 2"), 0); 38 EXPECT_LT(alphanumComp("Alpha 2", "Alpha 2A"), 0); 39 EXPECT_GT(alphanumComp("Alpha 2 B", "Alpha 2"), 0); 40 41 std::string str("Alpha 2"); 42 EXPECT_EQ(alphanumComp(str, "Alpha 2"), 0); 43 EXPECT_LT(alphanumComp(str, "Alpha 2A"), 0); 44 EXPECT_GT(alphanumComp("Alpha 2 B", str), 0); 45 } 46 47 TEST(AlphaNum, LessTest) 48 { 49 std::set<std::string, AlphanumLess<std::string>> sorted{ 50 "Alpha 10", "Alpha 2"}; 51 EXPECT_THAT(sorted, ElementsAreArray({"Alpha 2", "Alpha 10"})); 52 } 53 } // namespace 54