source: OGRE/trunk/ogrenew/Tests/OgreMain/src/RadixSort.cpp @ 692

Revision 692, 4.6 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

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-2005 The OGRE Team
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-----------------------------------------------------------------------------
24*/
25#include "RadixSortTests.h"
26#include "OgreRadixSort.h"
27#include "OgreMath.h"
28
29using namespace Ogre;
30
31// Regsiter the suite
32CPPUNIT_TEST_SUITE_REGISTRATION( RadixSortTests );
33
34void RadixSortTests::setUp()
35{
36        srand(time(0));
37}
38void RadixSortTests::tearDown()
39{
40}
41
42class FloatSortFunctor
43{
44public:
45        float operator()(const float& p) const
46        {
47                return p;
48        }
49
50};
51class IntSortFunctor
52{
53public:
54        int operator()(const int& p) const
55        {
56                return p;
57        }
58
59};
60
61class UnsignedIntSortFunctor
62{
63public:
64        unsigned int operator()(const unsigned int& p) const
65        {
66                return p;
67        }
68
69};
70
71
72void 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}
95void 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}
116void 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}
137void 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}
158void 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}
179void 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
Note: See TracBrowser for help on using the repository browser.