1#include <vector>
2#include "unary.h"
3#include <algorithm>
4
5#include "cppunit/cppunit_proxy.h"
6
7#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
8using namespace std;
9#endif
10
11//
12// TestCase class
13//
14class UnaryTest : public CPPUNIT_NS::TestCase
15{
16  CPPUNIT_TEST_SUITE(UnaryTest);
17#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
18  CPPUNIT_IGNORE;
19#endif
20  CPPUNIT_TEST(ucompos1);
21  CPPUNIT_TEST(ucompos2);
22  CPPUNIT_STOP_IGNORE;
23  CPPUNIT_TEST(unegate1);
24  CPPUNIT_TEST(unegate2);
25#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
26  CPPUNIT_IGNORE;
27#endif
28  CPPUNIT_TEST(unegate3);
29  CPPUNIT_TEST_SUITE_END();
30
31protected:
32  void ucompos1();
33  void ucompos2();
34  void unegate1();
35  void unegate2();
36  void unegate3();
37};
38
39CPPUNIT_TEST_SUITE_REGISTRATION(UnaryTest);
40
41//
42// tests implementation
43//
44void UnaryTest::unegate1()
45{
46  int array [3] = { 1, 2, 3 };
47  //unary_negate<odd>::argument_type arg_val = 0;
48  int* p = find_if((int*)array, (int*)array + 3, unary_negate<odd>(odd()));
49  CPPUNIT_ASSERT((p != array + 3));
50  CPPUNIT_ASSERT(*p==2);
51}
52void UnaryTest::unegate2()
53{
54  int array [3] = { 1, 2, 3 };
55  int* p = find_if((int*)array, (int*)array + 3, not1(odd()));
56  CPPUNIT_ASSERT(p != array + 3);
57  CPPUNIT_ASSERT(*p==2);
58}
59
60bool test_func(int param) {
61  return param < 3;
62}
63void UnaryTest::unegate3()
64{
65#if !defined (STLPORT) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
66  int array [3] = { 1, 2, 3 };
67  int* p = find_if((int*)array, (int*)array + 3, not1(ptr_fun(test_func)));
68  CPPUNIT_ASSERT(p != array + 3);
69  CPPUNIT_ASSERT(*p==3);
70#endif
71}
72
73void UnaryTest::ucompos1()
74{
75#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
76  int input [3] = { -1, -4, -16 };
77
78  double output[3];
79  transform((int*)input, (int*)input + 3, output, unary_compose<square_root, negate<int> >(square_root(), negate<int>()));
80
81  CPPUNIT_ASSERT(output[0]==1);
82  CPPUNIT_ASSERT(output[1]==2);
83  CPPUNIT_ASSERT(output[2]==4);
84#endif
85}
86void UnaryTest::ucompos2()
87{
88#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
89  int input [3] = { -1, -4, -16 };
90
91  double output [3];
92  transform((int*)input, (int*)input + 3, output, compose1(square_root(), negate<int>()));
93
94  CPPUNIT_ASSERT(output[0]==1);
95  CPPUNIT_ASSERT(output[1]==2);
96  CPPUNIT_ASSERT(output[2]==4);
97#endif
98}
99