ReactOS 0.4.15-dev-8064-gdaf8068
SortTest Class Reference
Inheritance diagram for SortTest:
Collaboration diagram for SortTest:

Protected Member Functions

void sort1 ()
 
void sort2 ()
 
void sort3 ()
 
void sort4 ()
 
void stblsrt1 ()
 
void stblsrt2 ()
 
void bad_predicate_detected ()
 

Static Protected Member Functions

static bool string_less (const char *a_, const char *b_)
 

Private Member Functions

 CPPUNIT_TEST_SUITE (SortTest)
 
 CPPUNIT_TEST (sort1)
 
 CPPUNIT_TEST (sort2)
 
 CPPUNIT_TEST (sort3)
 
 CPPUNIT_TEST (sort4)
 
 CPPUNIT_TEST (stblsrt1)
 
 CPPUNIT_TEST (stblsrt2)
 
 CPPUNIT_TEST_SUITE_END ()
 

Detailed Description

Definition at line 19 of file sort_test.cpp.

Member Function Documentation

◆ bad_predicate_detected()

void SortTest::bad_predicate_detected ( )
protected

◆ CPPUNIT_TEST() [1/6]

SortTest::CPPUNIT_TEST ( sort1  )
private

◆ CPPUNIT_TEST() [2/6]

SortTest::CPPUNIT_TEST ( sort2  )
private

◆ CPPUNIT_TEST() [3/6]

SortTest::CPPUNIT_TEST ( sort3  )
private

◆ CPPUNIT_TEST() [4/6]

SortTest::CPPUNIT_TEST ( sort4  )
private

◆ CPPUNIT_TEST() [5/6]

SortTest::CPPUNIT_TEST ( stblsrt1  )
private

◆ CPPUNIT_TEST() [6/6]

SortTest::CPPUNIT_TEST ( stblsrt2  )
private

◆ CPPUNIT_TEST_SUITE()

SortTest::CPPUNIT_TEST_SUITE ( SortTest  )
private

◆ CPPUNIT_TEST_SUITE_END()

SortTest::CPPUNIT_TEST_SUITE_END ( )
private

◆ sort1()

void SortTest::sort1 ( )
protected

Definition at line 113 of file sort_test.cpp.

114{
115 int numbers[6] = { 1, 50, -10, 11, 42, 19 };
116
117 sort(numbers, numbers + 6);
118 // -10 1 11 19 42 50
119 CPPUNIT_ASSERT(numbers[0]==-10);
120 CPPUNIT_ASSERT(numbers[1]==1);
121 CPPUNIT_ASSERT(numbers[2]==11);
122 CPPUNIT_ASSERT(numbers[3]==19);
123 CPPUNIT_ASSERT(numbers[4]==42);
124 CPPUNIT_ASSERT(numbers[5]==50);
125}
_STLP_MOVE_TO_STD_NAMESPACE void sort(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:993
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200

◆ sort2()

void SortTest::sort2 ( )
protected

Definition at line 127 of file sort_test.cpp.

128{
129 int numbers[] = { 1, 50, -10, 11, 42, 19 };
130
131 int count = sizeof(numbers) / sizeof(numbers[0]);
132 sort(numbers, numbers + count, greater<int>());
133
134 // 50 42 19 11 1 -10
135 CPPUNIT_ASSERT(numbers[5]==-10);
136 CPPUNIT_ASSERT(numbers[4]==1);
137 CPPUNIT_ASSERT(numbers[3]==11);
138 CPPUNIT_ASSERT(numbers[2]==19);
139 CPPUNIT_ASSERT(numbers[1]==42);
140 CPPUNIT_ASSERT(numbers[0]==50);
141}
GLuint GLuint GLsizei count
Definition: gl.h:1545

◆ sort3()

void SortTest::sort3 ( )
protected

Definition at line 143 of file sort_test.cpp.

144{
145 vector<bool> boolVector;
146
147 boolVector.push_back( true );
148 boolVector.push_back( false );
149
150 sort( boolVector.begin(), boolVector.end() );
151
152 CPPUNIT_ASSERT(boolVector[0]==false);
153 CPPUNIT_ASSERT(boolVector[1]==true);
154}
iterator end()
Definition: _vector.h:184
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
iterator begin()
Definition: _vector.h:182

◆ sort4()

void SortTest::sort4 ( )
protected

Definition at line 181 of file sort_test.cpp.

182{
183 bool copy_constructor_called = false;
184 SortTestAux instance(copy_constructor_called);
185 SortTestAux &r_instance = instance;
186 SortTestAux const& rc_instance = instance;
187
188 SortTestFunc(r_instance);
189 CPPUNIT_ASSERT(copy_constructor_called);
190 copy_constructor_called = false;
191 SortTestFunc(rc_instance);
192 CPPUNIT_ASSERT(copy_constructor_called);
193}
static HINSTANCE instance
Definition: main.c:40
void SortTestFunc(_Tp)
Definition: sort_test.cpp:178

◆ stblsrt1()

void SortTest::stblsrt1 ( )
protected

Definition at line 53 of file sort_test.cpp.

54{
55 //Check that stable_sort do sort
56 int numbers[6] = { 1, 50, -10, 11, 42, 19 };
57 stable_sort(numbers, numbers + 6);
58 //-10 1 11 19 42 50
59 CPPUNIT_ASSERT(numbers[0]==-10);
60 CPPUNIT_ASSERT(numbers[1]==1);
61 CPPUNIT_ASSERT(numbers[2]==11);
62 CPPUNIT_ASSERT(numbers[3]==19);
63 CPPUNIT_ASSERT(numbers[4]==42);
64 CPPUNIT_ASSERT(numbers[5]==50);
65
66 char const* letters[6] = {"bb", "aa", "ll", "dd", "qq", "cc" };
67 stable_sort(letters, letters + 6, string_less);
68 // aa bb cc dd ll qq
69 CPPUNIT_ASSERT( strcmp(letters[0], "aa") == 0 );
70 CPPUNIT_ASSERT( strcmp(letters[1], "bb") == 0 );
71 CPPUNIT_ASSERT( strcmp(letters[2], "cc") == 0 );
72 CPPUNIT_ASSERT( strcmp(letters[3], "dd") == 0 );
73 CPPUNIT_ASSERT( strcmp(letters[4], "ll") == 0 );
74 CPPUNIT_ASSERT( strcmp(letters[5], "qq") == 0 );
75}
_STLP_MOVE_TO_STD_NAMESPACE void stable_sort(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:1197
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
static bool string_less(const char *a_, const char *b_)
Definition: sort_test.cpp:42

◆ stblsrt2()

void SortTest::stblsrt2 ( )
protected

Definition at line 90 of file sort_test.cpp.

91{
92 //Check that stable_sort is stable:
93 Data datas[] = {
94 Data(0, 10),
95 Data(1, 8),
96 Data(2, 6),
97 Data(3, 6),
98 Data(4, 6),
99 Data(5, 4),
100 Data(6, 9)
101 };
102 stable_sort(datas, datas + 7);
103
104 CPPUNIT_ASSERT( datas[0] == Data(5, 4) );
105 CPPUNIT_ASSERT( datas[1] == Data(2, 6) );
106 CPPUNIT_ASSERT( datas[2] == Data(3, 6) );
107 CPPUNIT_ASSERT( datas[3] == Data(4, 6) );
108 CPPUNIT_ASSERT( datas[4] == Data(1, 8) );
109 CPPUNIT_ASSERT( datas[5] == Data(6, 9) );
110 CPPUNIT_ASSERT( datas[6] == Data(0, 10) );
111}

◆ string_less()

static bool SortTest::string_less ( const char a_,
const char b_ 
)
inlinestaticprotected

Definition at line 42 of file sort_test.cpp.

43 {
44 return strcmp(a_, b_) < 0 ? 1 : 0;
45 }

Referenced by stblsrt1().


The documentation for this class was generated from the following file: