ReactOS 0.4.15-dev-8002-gbbb3b00
rndshf_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 RndShuffleTest : public CPPUNIT_NS::TestCase
16{
18 {
19 public:
20 unsigned long operator()(unsigned long n_)
21 {
22 return rand() % n_;
23 }
24 };
29
30protected:
31 void rndshuf0();
32 void rndshuf2();
33};
34
36
37//
38// tests implementation
39//
41{
42 int numbers[6] = { 1, 2, 3, 4, 5, 6 };
43
44 random_shuffle(numbers, numbers + 6);
45
46 CPPUNIT_ASSERT(count(numbers, numbers+6, 1)==1);
47 CPPUNIT_ASSERT(count(numbers, numbers+6, 2)==1);
48 CPPUNIT_ASSERT(count(numbers, numbers+6, 3)==1);
49 CPPUNIT_ASSERT(count(numbers, numbers+6, 4)==1);
50 CPPUNIT_ASSERT(count(numbers, numbers+6, 5)==1);
51 CPPUNIT_ASSERT(count(numbers, numbers+6, 6)==1);
52}
54{
55 vector <int> v1(10);
56 __iota(v1.begin(), v1.end(), 0);
57
59 for(int i = 0; i < 3; i++)
60 {
61 random_shuffle(v1.begin(), v1.end(), r);
62 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 0)==1);
63 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 1)==1);
64 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 2)==1);
65 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 3)==1);
66 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 4)==1);
67 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 5)==1);
68 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 6)==1);
69 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 7)==1);
70 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 8)==1);
71 CPPUNIT_ASSERT(count(v1.begin(), v1.end(), 9)==1);
72 }
73}
_STLP_MOVE_TO_STD_NAMESPACE void random_shuffle(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:540
unsigned long operator()(unsigned long n_)
Definition: rndshf_test.cpp:20
CPPUNIT_TEST_SUITE(RndShuffleTest)
CPPUNIT_TEST(rndshuf2)
CPPUNIT_TEST(rndshuf0)
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLfloat GLfloat v1
Definition: glext.h:6062
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
void __iota(_It __first, _It __last, _Tp __val)
Definition: iota.h:8
Definition: features.h:417