|
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 <algorithm> |
|
18 #include <functional> |
|
19 |
|
20 #include "cppunit/cppunit_proxy.h" |
|
21 |
|
22 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) |
|
23 using namespace std; |
|
24 #endif |
|
25 |
|
26 // |
|
27 // TestCase class |
|
28 // |
|
29 class BnegateTest : public CPPUNIT_NS::TestCase |
|
30 { |
|
31 CPPUNIT_TEST_SUITE(BnegateTest); |
|
32 CPPUNIT_TEST(bnegate1); |
|
33 CPPUNIT_TEST(bnegate2); |
|
34 CPPUNIT_TEST_SUITE_END(); |
|
35 |
|
36 protected: |
|
37 void bnegate1(); |
|
38 void bnegate2(); |
|
39 }; |
|
40 |
|
41 CPPUNIT_TEST_SUITE_REGISTRATION(BnegateTest); |
|
42 |
|
43 // |
|
44 // tests implementation |
|
45 // |
|
46 void BnegateTest::bnegate1() |
|
47 { |
|
48 int array [4] = { 4, 9, 7, 1 }; |
|
49 |
|
50 sort(array, array + 4, binary_negate<greater<int> >(greater<int>())); |
|
51 CPPUNIT_ASSERT(array[0]==1); |
|
52 CPPUNIT_ASSERT(array[1]==4); |
|
53 CPPUNIT_ASSERT(array[2]==7); |
|
54 CPPUNIT_ASSERT(array[3]==9); |
|
55 } |
|
56 void BnegateTest::bnegate2() |
|
57 { |
|
58 int array [4] = { 4, 9, 7, 1 }; |
|
59 sort(array, array + 4, not2(greater<int>())); |
|
60 CPPUNIT_ASSERT(array[0]==1); |
|
61 CPPUNIT_ASSERT(array[1]==4); |
|
62 CPPUNIT_ASSERT(array[2]==7); |
|
63 CPPUNIT_ASSERT(array[3]==9); |
|
64 } |