1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "RadixSortTests.h"
|
---|
26 | #include "OgreRadixSort.h"
|
---|
27 | #include "OgreMath.h"
|
---|
28 |
|
---|
29 | using namespace Ogre;
|
---|
30 |
|
---|
31 | // Regsiter the suite
|
---|
32 | CPPUNIT_TEST_SUITE_REGISTRATION( RadixSortTests );
|
---|
33 |
|
---|
34 | void RadixSortTests::setUp()
|
---|
35 | {
|
---|
36 | srand(time(0));
|
---|
37 | }
|
---|
38 | void RadixSortTests::tearDown()
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 | class FloatSortFunctor
|
---|
43 | {
|
---|
44 | public:
|
---|
45 | float operator()(const float& p) const
|
---|
46 | {
|
---|
47 | return p;
|
---|
48 | }
|
---|
49 |
|
---|
50 | };
|
---|
51 | class IntSortFunctor
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | int operator()(const int& p) const
|
---|
55 | {
|
---|
56 | return p;
|
---|
57 | }
|
---|
58 |
|
---|
59 | };
|
---|
60 |
|
---|
61 | class UnsignedIntSortFunctor
|
---|
62 | {
|
---|
63 | public:
|
---|
64 | unsigned int operator()(const unsigned int& p) const
|
---|
65 | {
|
---|
66 | return p;
|
---|
67 | }
|
---|
68 |
|
---|
69 | };
|
---|
70 |
|
---|
71 |
|
---|
72 | void RadixSortTests::testFloatVector()
|
---|
73 | {
|
---|
74 | std::vector<float> container;
|
---|
75 | FloatSortFunctor func;
|
---|
76 | RadixSort<std::vector<float>, float, float> sorter;
|
---|
77 |
|
---|
78 | for (int i = 0; i < 1000; ++i)
|
---|
79 | {
|
---|
80 | container.push_back((float)Math::RangeRandom(-1e10, 1e10));
|
---|
81 | }
|
---|
82 |
|
---|
83 | sorter.sort(container, func);
|
---|
84 |
|
---|
85 | std::vector<float>::iterator v = container.begin();
|
---|
86 | float lastValue = *v++;
|
---|
87 | for (;v != container.end(); ++v)
|
---|
88 | {
|
---|
89 | CPPUNIT_ASSERT(*v >= lastValue);
|
---|
90 | lastValue = *v;
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | }
|
---|
95 | void RadixSortTests::testFloatList()
|
---|
96 | {
|
---|
97 | std::list<float> container;
|
---|
98 | FloatSortFunctor func;
|
---|
99 | RadixSort<std::list<float>, float, float> sorter;
|
---|
100 |
|
---|
101 | for (int i = 0; i < 1000; ++i)
|
---|
102 | {
|
---|
103 | container.push_back((float)Math::RangeRandom(-1e10, 1e10));
|
---|
104 | }
|
---|
105 |
|
---|
106 | sorter.sort(container, func);
|
---|
107 |
|
---|
108 | std::list<float>::iterator v = container.begin();
|
---|
109 | float lastValue = *v++;
|
---|
110 | for (;v != container.end(); ++v)
|
---|
111 | {
|
---|
112 | CPPUNIT_ASSERT(*v >= lastValue);
|
---|
113 | lastValue = *v;
|
---|
114 | }
|
---|
115 | }
|
---|
116 | void RadixSortTests::testUnsignedIntList()
|
---|
117 | {
|
---|
118 | std::list<unsigned int> container;
|
---|
119 | UnsignedIntSortFunctor func;
|
---|
120 | RadixSort<std::list<unsigned int>, unsigned int, unsigned int> sorter;
|
---|
121 |
|
---|
122 | for (int i = 0; i < 1000; ++i)
|
---|
123 | {
|
---|
124 | container.push_back((unsigned int)Math::RangeRandom(0, 1e10));
|
---|
125 | }
|
---|
126 |
|
---|
127 | sorter.sort(container, func);
|
---|
128 |
|
---|
129 | std::list<unsigned int>::iterator v = container.begin();
|
---|
130 | unsigned int lastValue = *v++;
|
---|
131 | for (;v != container.end(); ++v)
|
---|
132 | {
|
---|
133 | CPPUNIT_ASSERT(*v >= lastValue);
|
---|
134 | lastValue = *v;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | void RadixSortTests::testIntList()
|
---|
138 | {
|
---|
139 | std::list<int> container;
|
---|
140 | IntSortFunctor func;
|
---|
141 | RadixSort<std::list<int>, int, int> sorter;
|
---|
142 |
|
---|
143 | for (int i = 0; i < 1000; ++i)
|
---|
144 | {
|
---|
145 | container.push_back((int)Math::RangeRandom(-1e10, 1e10));
|
---|
146 | }
|
---|
147 |
|
---|
148 | sorter.sort(container, func);
|
---|
149 |
|
---|
150 | std::list<int>::iterator v = container.begin();
|
---|
151 | int lastValue = *v++;
|
---|
152 | for (;v != container.end(); ++v)
|
---|
153 | {
|
---|
154 | CPPUNIT_ASSERT(*v >= lastValue);
|
---|
155 | lastValue = *v;
|
---|
156 | }
|
---|
157 | }
|
---|
158 | void RadixSortTests::testUnsignedIntVector()
|
---|
159 | {
|
---|
160 | std::vector<unsigned int> container;
|
---|
161 | UnsignedIntSortFunctor func;
|
---|
162 | RadixSort<std::vector<unsigned int>, unsigned int, unsigned int> sorter;
|
---|
163 |
|
---|
164 | for (int i = 0; i < 1000; ++i)
|
---|
165 | {
|
---|
166 | container.push_back((unsigned int)Math::RangeRandom(0, 1e10));
|
---|
167 | }
|
---|
168 |
|
---|
169 | sorter.sort(container, func);
|
---|
170 |
|
---|
171 | std::vector<unsigned int>::iterator v = container.begin();
|
---|
172 | unsigned int lastValue = *v++;
|
---|
173 | for (;v != container.end(); ++v)
|
---|
174 | {
|
---|
175 | CPPUNIT_ASSERT(*v >= lastValue);
|
---|
176 | lastValue = *v;
|
---|
177 | }
|
---|
178 | }
|
---|
179 | void RadixSortTests::testIntVector()
|
---|
180 | {
|
---|
181 | std::vector<int> container;
|
---|
182 | IntSortFunctor func;
|
---|
183 | RadixSort<std::vector<int>, int, int> sorter;
|
---|
184 |
|
---|
185 | for (int i = 0; i < 1000; ++i)
|
---|
186 | {
|
---|
187 | container.push_back((int)Math::RangeRandom(-1e10, 1e10));
|
---|
188 | }
|
---|
189 |
|
---|
190 | sorter.sort(container, func);
|
---|
191 |
|
---|
192 | std::vector<int>::iterator v = container.begin();
|
---|
193 | int lastValue = *v++;
|
---|
194 | for (;v != container.end(); ++v)
|
---|
195 | {
|
---|
196 | CPPUNIT_ASSERT(*v >= lastValue);
|
---|
197 | lastValue = *v;
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 |
|
---|