ReactOS 0.4.16-dev-340-g0540c21
rotate_test.cpp
Go to the documentation of this file.
1#include <numeric>
2#include <vector>
3#include <algorithm>
4
5#include "iota.h"
7
8#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
9using namespace std;
10#endif
11
12//
13// TestCase class
14//
15class RotateTest : public CPPUNIT_NS::TestCase
16{
23
24protected:
25 void rotate0();
26 void rotate1();
27 void rotcopy0();
28 void rotcopy1();
29};
30
32
33//
34// tests implementation
35//
37{
38 int numbers[6] = { 0, 1, 2, 3, 4, 5 };
39 // 3 4 5 0 1 2
40 rotate((int*)numbers, numbers + 3, numbers + 6);
41 CPPUNIT_ASSERT(numbers[0]==3);
42 CPPUNIT_ASSERT(numbers[1]==4);
43 CPPUNIT_ASSERT(numbers[2]==5);
44 CPPUNIT_ASSERT(numbers[3]==0);
45 CPPUNIT_ASSERT(numbers[4]==1);
46 CPPUNIT_ASSERT(numbers[5]==2);
47}
49{
50 vector <int> v1(10);
51 __iota(v1.begin(), v1.end(), 0);
52
53 rotate(v1.begin(), v1.begin()+1, v1.end());
54 CPPUNIT_ASSERT(v1[0]==1);
55 CPPUNIT_ASSERT(v1[1]==2);
56 CPPUNIT_ASSERT(v1[2]==3);
57 CPPUNIT_ASSERT(v1[3]==4);
58 CPPUNIT_ASSERT(v1[4]==5);
59 CPPUNIT_ASSERT(v1[5]==6);
60 CPPUNIT_ASSERT(v1[6]==7);
61 CPPUNIT_ASSERT(v1[7]==8);
62 CPPUNIT_ASSERT(v1[8]==9);
63 CPPUNIT_ASSERT(v1[9]==0);
64
65 rotate(v1.begin(), v1.begin()+2, v1.end());
66 CPPUNIT_ASSERT(v1[0]==3);
67 CPPUNIT_ASSERT(v1[1]==4);
68 CPPUNIT_ASSERT(v1[2]==5);
69 CPPUNIT_ASSERT(v1[3]==6);
70 CPPUNIT_ASSERT(v1[4]==7);
71 CPPUNIT_ASSERT(v1[5]==8);
72 CPPUNIT_ASSERT(v1[6]==9);
73 CPPUNIT_ASSERT(v1[7]==0);
74 CPPUNIT_ASSERT(v1[8]==1);
75 CPPUNIT_ASSERT(v1[9]==2);
76
77 rotate(v1.begin(), v1.begin()+7, v1.end());
78 CPPUNIT_ASSERT(v1[0]==0);
79 CPPUNIT_ASSERT(v1[1]==1);
80 CPPUNIT_ASSERT(v1[2]==2);
81 CPPUNIT_ASSERT(v1[3]==3);
82 CPPUNIT_ASSERT(v1[4]==4);
83 CPPUNIT_ASSERT(v1[5]==5);
84 CPPUNIT_ASSERT(v1[6]==6);
85 CPPUNIT_ASSERT(v1[7]==7);
86 CPPUNIT_ASSERT(v1[8]==8);
87 CPPUNIT_ASSERT(v1[9]==9);
88
89}
91{
92 int numbers[6] = { 0, 1, 2, 3, 4, 5 };
93
94 int result[6];
95 rotate_copy((int*)numbers, (int*)numbers + 3, (int*)numbers + 6, (int*)result);
96 // 3 4 5 0 1 2
100 CPPUNIT_ASSERT(result[3]==0);
101 CPPUNIT_ASSERT(result[4]==1);
102 CPPUNIT_ASSERT(result[5]==2);
103}
105{
106 vector <int> v1(10);
107 __iota(v1.begin(), v1.end(), 0);
108 vector <int> v2(v1.size());
109
110 rotate_copy(v1.begin(), v1.begin()+1, v1.end(), v2.begin());
111 CPPUNIT_ASSERT(v2[0]==1);
112 CPPUNIT_ASSERT(v2[1]==2);
113 CPPUNIT_ASSERT(v2[2]==3);
114 CPPUNIT_ASSERT(v2[3]==4);
115 CPPUNIT_ASSERT(v2[4]==5);
116 CPPUNIT_ASSERT(v2[5]==6);
117 CPPUNIT_ASSERT(v2[6]==7);
118 CPPUNIT_ASSERT(v2[7]==8);
119 CPPUNIT_ASSERT(v2[8]==9);
120 CPPUNIT_ASSERT(v2[9]==0);
121
122 rotate_copy(v1.begin(), v1.begin()+3, v1.end(), v2.begin());
123 CPPUNIT_ASSERT(v2[0]==3);
124 CPPUNIT_ASSERT(v2[1]==4);
125 CPPUNIT_ASSERT(v2[2]==5);
126 CPPUNIT_ASSERT(v2[3]==6);
127 CPPUNIT_ASSERT(v2[4]==7);
128 CPPUNIT_ASSERT(v2[5]==8);
129 CPPUNIT_ASSERT(v2[6]==9);
130 CPPUNIT_ASSERT(v2[7]==0);
131 CPPUNIT_ASSERT(v2[8]==1);
132 CPPUNIT_ASSERT(v2[9]==2);
133}
_STLP_MOVE_TO_STD_NAMESPACE void rotate(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last)
Definition: _algo.c:519
_OutputIter rotate_copy(_ForwardIter __first, _ForwardIter __middle, _ForwardIter __last, _OutputIter __result)
Definition: _algo.h:355
CPPUNIT_TEST(rotcopy0)
void rotate0()
Definition: rotate_test.cpp:36
CPPUNIT_TEST(rotate0)
void rotcopy1()
CPPUNIT_TEST_SUITE(RotateTest)
void rotcopy0()
Definition: rotate_test.cpp:90
CPPUNIT_TEST(rotcopy1)
CPPUNIT_TEST(rotate1)
void rotate1()
Definition: rotate_test.cpp:48
CPPUNIT_TEST_SUITE_END()
#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
GLfloat GLfloat GLfloat v2
Definition: glext.h:6063
GLuint64EXT * result
Definition: glext.h:11304
void __iota(_It __first, _It __last, _Tp __val)
Definition: iota.h:8
Definition: features.h:417