1#include <vector>
2#include <algorithm>
3#include <functional>
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 InplaceTest : public CPPUNIT_NS::TestCase
15{
16  CPPUNIT_TEST_SUITE(InplaceTest);
17  CPPUNIT_TEST(inplmrg1);
18  CPPUNIT_TEST(inplmrg2);
19  CPPUNIT_TEST_SUITE_END();
20
21protected:
22  void inplmrg1();
23  void inplmrg2();
24};
25
26CPPUNIT_TEST_SUITE_REGISTRATION(InplaceTest);
27
28//
29// tests implementation
30//
31void InplaceTest::inplmrg1()
32{
33  int numbers[6] = { 1, 10, 42, 3, 16, 32 };
34  inplace_merge(numbers, numbers + 3, numbers + 6);
35
36  CPPUNIT_ASSERT(numbers[0]==1);
37  CPPUNIT_ASSERT(numbers[1]==3);
38  CPPUNIT_ASSERT(numbers[2]==10);
39  CPPUNIT_ASSERT(numbers[3]==16);
40  CPPUNIT_ASSERT(numbers[4]==32);
41  CPPUNIT_ASSERT(numbers[5]==42);
42}
43void InplaceTest::inplmrg2()
44{
45  vector<size_t> v1(10);
46  for(size_t i = 0; i < v1.size(); ++i)
47    v1[i] =(v1.size() - i - 1) % 5;
48
49  inplace_merge(v1.begin(), v1.begin() + 5, v1.end(), greater<size_t>());
50
51  CPPUNIT_ASSERT(v1[0]==4);
52  CPPUNIT_ASSERT(v1[1]==4);
53  CPPUNIT_ASSERT(v1[2]==3);
54  CPPUNIT_ASSERT(v1[3]==3);
55  CPPUNIT_ASSERT(v1[4]==2);
56  CPPUNIT_ASSERT(v1[5]==2);
57  CPPUNIT_ASSERT(v1[6]==1);
58  CPPUNIT_ASSERT(v1[7]==1);
59  CPPUNIT_ASSERT(v1[8]==0);
60  CPPUNIT_ASSERT(v1[9]==0);
61}
62