ReactOS 0.4.15-dev-7961-gdcf9eb0
nthelm_test.cpp
Go to the documentation of this file.
1#include <vector>
2#include <algorithm>
3#include <functional>
4
6
7#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
8using namespace std;
9#endif
10
11//
12// TestCase class
13//
14class NthElemTest : public CPPUNIT_NS::TestCase
15{
21
22protected:
23 void nthelem0();
24 void nthelem1();
25 void nthelem2();
26};
27
29
30//
31// tests implementation
32//
34{
35 int numbers[7] = { 5, 2, 4, 1, 0, 3 ,77};
36 nth_element(numbers, numbers + 3, numbers + 6);
37
38 CPPUNIT_ASSERT(numbers[0]==1);
39 CPPUNIT_ASSERT(numbers[1]==0);
40 CPPUNIT_ASSERT(numbers[2]==2);
41 CPPUNIT_ASSERT(numbers[3]==3);
42 CPPUNIT_ASSERT(numbers[4]==4);
43 CPPUNIT_ASSERT(numbers[5]==5);
44}
46{
47 //6 8 5 1 7 4 1 5 2 6
48 //1 1 4 2 5 5 6 7 8 6
49 int numbers[10] = { 6, 8, 5, 1, 7, 4, 1, 5, 2, 6 };
50
51 vector <int> v1(numbers, numbers+10);
52 nth_element(v1.begin(), v1.begin() + v1.size() / 2, v1.end());
53
54 CPPUNIT_ASSERT(v1[0]==1);
55 CPPUNIT_ASSERT(v1[1]==1);
56 CPPUNIT_ASSERT(v1[2]==4);
57 CPPUNIT_ASSERT(v1[3]==2);
58 CPPUNIT_ASSERT(v1[4]==5);
59 CPPUNIT_ASSERT(v1[5]==5);
60 CPPUNIT_ASSERT(v1[6]==6);
61 CPPUNIT_ASSERT(v1[7]==7);
62 CPPUNIT_ASSERT(v1[8]==8);
63 CPPUNIT_ASSERT(v1[9]==6);
64}
66{
67 //4 5 4 2 1 7 4 3 1 6
68 //6 7 4 4 5 4 3 2 1 1
69
70 int numbers[10] = { 4, 5, 4, 2, 1, 7, 4, 3, 1, 6 };
71 vector <int> v1(numbers, numbers+10);
72 nth_element(v1.begin(), v1.begin() + v1.size() / 2, v1.end(), greater<int>());
73
74 CPPUNIT_ASSERT(v1[0]==6);
75 CPPUNIT_ASSERT(v1[1]==7);
76 CPPUNIT_ASSERT(v1[2]==4);
77 CPPUNIT_ASSERT(v1[3]==4);
78 CPPUNIT_ASSERT(v1[4]==5);
79 CPPUNIT_ASSERT(v1[5]==4);
80 CPPUNIT_ASSERT(v1[6]==3);
81 CPPUNIT_ASSERT(v1[7]==2);
82 CPPUNIT_ASSERT(v1[8]==1);
83 CPPUNIT_ASSERT(v1[9]==1);
84}
_STLP_MOVE_TO_STD_NAMESPACE void nth_element(_RandomAccessIter __first, _RandomAccessIter __nth, _RandomAccessIter __last)
Definition: _algo.c:1335
void nthelem0()
Definition: nthelm_test.cpp:33
void nthelem2()
Definition: nthelm_test.cpp:65
CPPUNIT_TEST_SUITE(NthElemTest)
CPPUNIT_TEST(nthelem2)
CPPUNIT_TEST(nthelem0)
void nthelem1()
Definition: nthelm_test.cpp:45
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(nthelem1)
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLfloat GLfloat v1
Definition: glext.h:6062
Definition: features.h:417