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