sl@0
|
1 |
#include <algorithm>
|
sl@0
|
2 |
#include <functional>
|
sl@0
|
3 |
|
sl@0
|
4 |
#include "cppunit/cppunit_proxy.h"
|
sl@0
|
5 |
|
sl@0
|
6 |
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
|
sl@0
|
7 |
using namespace std;
|
sl@0
|
8 |
#endif
|
sl@0
|
9 |
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// TestCase class
|
sl@0
|
12 |
//
|
sl@0
|
13 |
class BnegateTest : public CPPUNIT_NS::TestCase
|
sl@0
|
14 |
{
|
sl@0
|
15 |
CPPUNIT_TEST_SUITE(BnegateTest);
|
sl@0
|
16 |
CPPUNIT_TEST(bnegate1);
|
sl@0
|
17 |
CPPUNIT_TEST(bnegate2);
|
sl@0
|
18 |
CPPUNIT_TEST_SUITE_END();
|
sl@0
|
19 |
|
sl@0
|
20 |
protected:
|
sl@0
|
21 |
void bnegate1();
|
sl@0
|
22 |
void bnegate2();
|
sl@0
|
23 |
};
|
sl@0
|
24 |
|
sl@0
|
25 |
CPPUNIT_TEST_SUITE_REGISTRATION(BnegateTest);
|
sl@0
|
26 |
|
sl@0
|
27 |
//
|
sl@0
|
28 |
// tests implementation
|
sl@0
|
29 |
//
|
sl@0
|
30 |
void BnegateTest::bnegate1()
|
sl@0
|
31 |
{
|
sl@0
|
32 |
int array [4] = { 4, 9, 7, 1 };
|
sl@0
|
33 |
|
sl@0
|
34 |
sort(array, array + 4, binary_negate<greater<int> >(greater<int>()));
|
sl@0
|
35 |
CPPUNIT_ASSERT(array[0]==1);
|
sl@0
|
36 |
CPPUNIT_ASSERT(array[1]==4);
|
sl@0
|
37 |
CPPUNIT_ASSERT(array[2]==7);
|
sl@0
|
38 |
CPPUNIT_ASSERT(array[3]==9);
|
sl@0
|
39 |
}
|
sl@0
|
40 |
void BnegateTest::bnegate2()
|
sl@0
|
41 |
{
|
sl@0
|
42 |
int array [4] = { 4, 9, 7, 1 };
|
sl@0
|
43 |
sort(array, array + 4, not2(greater<int>()));
|
sl@0
|
44 |
CPPUNIT_ASSERT(array[0]==1);
|
sl@0
|
45 |
CPPUNIT_ASSERT(array[1]==4);
|
sl@0
|
46 |
CPPUNIT_ASSERT(array[2]==7);
|
sl@0
|
47 |
CPPUNIT_ASSERT(array[3]==9);
|
sl@0
|
48 |
}
|