Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tests/OgreMain/src/RadixSort.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

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