31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include <vector>
|
|
18 |
#include "unary.h"
|
|
19 |
#include <algorithm>
|
|
20 |
|
|
21 |
#include "cppunit/cppunit_proxy.h"
|
|
22 |
|
|
23 |
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
|
|
24 |
using namespace std;
|
|
25 |
#endif
|
|
26 |
|
|
27 |
//
|
|
28 |
// TestCase class
|
|
29 |
//
|
|
30 |
class UnaryTest : public CPPUNIT_NS::TestCase
|
|
31 |
{
|
|
32 |
CPPUNIT_TEST_SUITE(UnaryTest);
|
|
33 |
#if !defined (STLPORT) || defined (_STLP_NO_EXTENSIONS)
|
|
34 |
CPPUNIT_IGNORE;
|
|
35 |
#endif
|
|
36 |
CPPUNIT_TEST(ucompos1);
|
|
37 |
CPPUNIT_TEST(ucompos2);
|
|
38 |
CPPUNIT_STOP_IGNORE;
|
|
39 |
CPPUNIT_TEST(unegate1);
|
|
40 |
CPPUNIT_TEST(unegate2);
|
|
41 |
#if defined (STLPORT) && !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
42 |
CPPUNIT_IGNORE;
|
|
43 |
#endif
|
|
44 |
CPPUNIT_TEST(unegate3);
|
|
45 |
CPPUNIT_TEST_SUITE_END();
|
|
46 |
|
|
47 |
protected:
|
|
48 |
void ucompos1();
|
|
49 |
void ucompos2();
|
|
50 |
void unegate1();
|
|
51 |
void unegate2();
|
|
52 |
void unegate3();
|
|
53 |
};
|
|
54 |
|
|
55 |
CPPUNIT_TEST_SUITE_REGISTRATION(UnaryTest);
|
|
56 |
|
|
57 |
//
|
|
58 |
// tests implementation
|
|
59 |
//
|
|
60 |
void UnaryTest::unegate1()
|
|
61 |
{
|
|
62 |
int array [3] = { 1, 2, 3 };
|
|
63 |
//unary_negate<odd>::argument_type arg_val = 0;
|
|
64 |
int* p = find_if((int*)array, (int*)array + 3, unary_negate<odd>(odd()));
|
|
65 |
CPPUNIT_ASSERT((p != array + 3));
|
|
66 |
CPPUNIT_ASSERT(*p==2);
|
|
67 |
}
|
|
68 |
void UnaryTest::unegate2()
|
|
69 |
{
|
|
70 |
int array [3] = { 1, 2, 3 };
|
|
71 |
int* p = find_if((int*)array, (int*)array + 3, not1(odd()));
|
|
72 |
CPPUNIT_ASSERT(p != array + 3);
|
|
73 |
CPPUNIT_ASSERT(*p==2);
|
|
74 |
}
|
|
75 |
|
|
76 |
bool test_func(int param) {
|
|
77 |
return param < 3;
|
|
78 |
}
|
|
79 |
void UnaryTest::unegate3()
|
|
80 |
{
|
|
81 |
#if !defined (STLPORT) || defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
82 |
int array [3] = { 1, 2, 3 };
|
|
83 |
int* p = find_if((int*)array, (int*)array + 3, not1(ptr_fun(test_func)));
|
|
84 |
CPPUNIT_ASSERT(p != array + 3);
|
|
85 |
CPPUNIT_ASSERT(*p==3);
|
|
86 |
#endif
|
|
87 |
}
|
|
88 |
|
|
89 |
void UnaryTest::ucompos1()
|
|
90 |
{
|
|
91 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
92 |
int input [3] = { -1, -4, -16 };
|
|
93 |
|
|
94 |
double output[3];
|
|
95 |
transform((int*)input, (int*)input + 3, output, unary_compose<square_root, negate<int> >(square_root(), negate<int>()));
|
|
96 |
|
|
97 |
CPPUNIT_ASSERT(output[0]==1);
|
|
98 |
CPPUNIT_ASSERT(output[1]==2);
|
|
99 |
CPPUNIT_ASSERT(output[2]==4);
|
|
100 |
#endif
|
|
101 |
}
|
|
102 |
void UnaryTest::ucompos2()
|
|
103 |
{
|
|
104 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
105 |
int input [3] = { -1, -4, -16 };
|
|
106 |
|
|
107 |
double output [3];
|
|
108 |
transform((int*)input, (int*)input + 3, output, compose1(square_root(), negate<int>()));
|
|
109 |
|
|
110 |
CPPUNIT_ASSERT(output[0]==1);
|
|
111 |
CPPUNIT_ASSERT(output[1]==2);
|
|
112 |
CPPUNIT_ASSERT(output[2]==4);
|
|
113 |
#endif
|
|
114 |
}
|