ReactOS 0.4.15-dev-8058-ga7cbb60
generator_test.cpp
Go to the documentation of this file.
1#include <vector>
2#include <algorithm>
3#include "fadapter.h"
4#include "fib.h"
5
7
8#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
9using namespace std;
10#endif
11
12//
13// TestCase class
14//
15class GeneratorTest : public CPPUNIT_NS::TestCase
16{
23
24protected:
25 void gener1();
26 void gener2();
27 void genern1();
28 void genern2();
29};
30
32
33//
34// tests implementation
35//
36
37static int cxxrand() { return rand();}
38
40{
41 int numbers[10];
42#if defined(__MVS__)
43 generate(numbers, numbers + 10, ptr_gen(cxxrand));
44#else
45 generate(numbers, numbers + 10, cxxrand);
46#endif
47 // any suggestions?
48}
50{
51 vector <int> v1(10);
52 Fibonacci generator;
53 generate(v1.begin(), v1.end(), generator);
54
55 CPPUNIT_ASSERT(v1[0]==1);
56 CPPUNIT_ASSERT(v1[1]==1);
57 CPPUNIT_ASSERT(v1[2]==2);
58 CPPUNIT_ASSERT(v1[3]==3);
59 CPPUNIT_ASSERT(v1[4]==5);
60 CPPUNIT_ASSERT(v1[5]==8);
61 CPPUNIT_ASSERT(v1[6]==13);
62 CPPUNIT_ASSERT(v1[7]==21);
63 CPPUNIT_ASSERT(v1[8]==34);
64 CPPUNIT_ASSERT(v1[9]==55);
65}
67{
68#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
69 //*TY 07/18/98 - added conditional
70 // since ptr_gen() is not defined under this condition
71 // (see xfunction.h)
72 vector <int> v1(10);
73 generate_n(v1.begin(), v1.size(), ptr_gen(cxxrand));
74#endif //_STLP_MEMBER_POINTER_PARAM_BUG //*TY 07/18/98 - added
75}
77{
78 vector <int> v1(10);
79 Fibonacci generator;
80 generate_n(v1.begin(), v1.size(), generator);
81
82 CPPUNIT_ASSERT(v1[0]==1);
83 CPPUNIT_ASSERT(v1[1]==1);
84 CPPUNIT_ASSERT(v1[2]==2);
85 CPPUNIT_ASSERT(v1[3]==3);
86 CPPUNIT_ASSERT(v1[4]==5);
87 CPPUNIT_ASSERT(v1[5]==8);
88 CPPUNIT_ASSERT(v1[6]==13);
89 CPPUNIT_ASSERT(v1[7]==21);
90 CPPUNIT_ASSERT(v1[8]==34);
91 CPPUNIT_ASSERT(v1[9]==55);
92}
_STLP_INLINE_LOOP void generate_n(_OutputIter __first, _Size __n, _Generator __gen)
Definition: _algo.h:230
Definition: fib.h:4
CPPUNIT_TEST(gener1)
CPPUNIT_TEST_SUITE(GeneratorTest)
CPPUNIT_TEST(gener2)
CPPUNIT_TEST(genern2)
CPPUNIT_TEST(genern1)
#define CPPUNIT_TEST_SUITE_REGISTRATION(X)
Definition: cppunit_mini.h:193
#define CPPUNIT_ASSERT(X)
Definition: cppunit_mini.h:200
pointer_to_void_function< Result > ptr_gen(Result(*x)())
Definition: fadapter.h:39
static int cxxrand()
GLfloat GLfloat v1
Definition: glext.h:6062
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
Definition: features.h:417
static int generate
Definition: xmllint.c:164