source: filezilla/trunk/fuentes/tests/cmpnatural.cpp @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 6.5 KB
Line 
1#include <libfilezilla.h>
2#include <wx/imaglist.h>
3#include <wx/scrolwin.h>
4#include <wx/listctrl.h>
5#include <../interface/filelistctrl.h>
6
7#include <cppunit/extensions/HelperMacros.h>
8#include <list>
9
10/*
11 * This testsuite asserts the correctness of the
12 * functions handling natural sort
13 */
14
15class CNaturalSortTest : public CppUnit::TestFixture
16{
17        CPPUNIT_TEST_SUITE(CNaturalSortTest);
18        CPPUNIT_TEST(testEmpty);
19        CPPUNIT_TEST(testCaseInsensitive);
20        CPPUNIT_TEST(testString);
21        CPPUNIT_TEST(testNumber);
22        CPPUNIT_TEST(testMixed);
23        CPPUNIT_TEST(testSeq);
24        CPPUNIT_TEST(testPair);
25        CPPUNIT_TEST(testFractional);
26        CPPUNIT_TEST_SUITE_END();
27
28public:
29        void setUp() {}
30        void tearDown() {}
31
32        void testEmpty();
33        void testCaseInsensitive();
34        void testString();
35        void testNumber();
36        void testMixed();
37        void testSeq();
38        void testPair();
39        void testFractional();
40};
41
42CPPUNIT_TEST_SUITE_REGISTRATION(CNaturalSortTest);
43
44void CNaturalSortTest::testEmpty()
45{
46        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T(""), _T("")) == 0);
47        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T(""), _T("x")) < 0);
48        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("x"), _T("")) > 0);
49}
50
51void CNaturalSortTest::testCaseInsensitive()
52{
53        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a"), _T("A")) == 0);
54        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("B"), _T("b")) == 0);
55        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a"), _T("B")) < 0);
56        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("A"), _T("b")) < 0);
57        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("afFasFAc"), _T("aFfaSFaC")) == 0);
58}
59
60void CNaturalSortTest::testString()
61{
62        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a"), _T("b")) < 0);
63        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("b"), _T("a")) > 0);
64        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a"), _T("ab")) < 0);
65        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("ab"), _T("a")) > 0);
66        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("affasfac"), _T("affasfac")) == 0);
67}
68
69void CNaturalSortTest::testNumber()
70{
71        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1"), _T("1")) == 0);
72        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1"), _T("2")) < 0);
73        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("2"), _T("1")) > 0);
74        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("15"), _T("25")) < 0);
75        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("25"), _T("15")) > 0);
76        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("15"), _T("17")) < 0);
77        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("17"), _T("15")) > 0);
78        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1"), _T("10")) < 0);
79        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10"), _T("1")) > 0);
80        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("2"), _T("17")) < 0);
81        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("17"), _T("2")) > 0);
82        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("2"), _T("02")) < 0);
83        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("02"), _T("2")) > 0);
84        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("02"), _T("1")) > 0);
85        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1"), _T("02")) < 0);
86        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("02"), _T("3")) < 0);
87        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("3"), _T("02")) > 0);
88        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("25"), _T("021")) > 0);
89        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("021"), _T("25")) < 0);
90        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("2100"), _T("02005")) > 0);
91        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("02005"), _T("2100")) < 0);
92        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("010"), _T("02")) > 0);
93}
94
95void CNaturalSortTest::testMixed()
96{
97        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("0"), _T("a")) < 0);
98        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a"), _T("0")) > 0);
99        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("abc1xx"), _T("abc2xx")) < 0);
100        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("abc1bb"), _T("abc2aa")) < 0);
101        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("abc2"), _T("1")) > 0);
102        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10abc"), _T("10def")) < 0);
103        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10def"), _T("10abc")) > 0);
104        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10abc2"), _T("10abc3")) < 0);
105        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10abc3"), _T("10abc2")) > 0);
106        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10abc"), _T("10abc3")) < 0);
107        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10abc3"), _T("10abc")) > 0);
108        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1"), _T("1abc")) < 0);
109        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1abc"), _T("1")) > 0);
110        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("2"), _T("1abc")) > 0);
111        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1abc"), _T("2")) < 0);
112        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1def"), _T("10abc")) < 0);
113        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("10abc"), _T("1def")) > 0);
114}
115
116void CNaturalSortTest::testSeq()
117{
118        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a"), _T("a0")) < 0);
119        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a0"), _T("a1")) < 0);
120        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a1"), _T("a1a")) < 0);
121        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a1a"), _T("a1b")) < 0);
122        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a1b"), _T("a2")) < 0);
123        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a2"), _T("a10")) < 0);
124        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("a10"), _T("a20")) < 0);
125}
126
127void CNaturalSortTest::testPair()
128{
129        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("x2-g8"), _T("x2-y7")) < 0);
130        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("x2-y7"), _T("x2-y08")) < 0);
131        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("x2-y08"), _T("x8-y8")) < 0);
132}
133
134void CNaturalSortTest::testFractional()
135{
136        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1.001"), _T("1.002")) < 0);
137        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1.002"), _T("1.010")) < 0);
138        //CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1.010"), _T("1.02")) < 0);   //this fraction case would break 010 > 02
139        //CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1.02"), _T("1.1")) < 0);     //this fraction case would break 02 > 1
140        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1.1"), _T("1.3")) < 0);
141        CPPUNIT_ASSERT(CFileListCtrlSortBase::CmpNatural(_T("1.3"), _T("1.15")) < 0);
142}
Note: See TracBrowser for help on using the repository browser.