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