1#include <vector>
2#include <algorithm>
3#include "fadapter.h"
4#include "fib.h"
5
6#include "cppunit/cppunit_proxy.h"
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{
17  CPPUNIT_TEST_SUITE(GeneratorTest);
18  CPPUNIT_TEST(gener1);
19  CPPUNIT_TEST(gener2);
20  CPPUNIT_TEST(genern1);
21  CPPUNIT_TEST(genern2);
22  CPPUNIT_TEST_SUITE_END();
23
24protected:
25  void gener1();
26  void gener2();
27  void genern1();
28  void genern2();
29};
30
31CPPUNIT_TEST_SUITE_REGISTRATION(GeneratorTest);
32
33//
34// tests implementation
35//
36
37static  int cxxrand() { return rand();}
38
39void GeneratorTest::gener1()
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}
49void GeneratorTest::gener2()
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}
66void GeneratorTest::genern1()
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}
76void GeneratorTest::genern2()
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}
93