aboutsummaryrefslogtreecommitdiff
path: root/test/unit/inplace_test.cpp
blob: 2c9bd99c399f2c12dd0d99b17ee5f16b7ca6ae11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <vector>
#include <algorithm>
#include <functional>

#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

//
// TestCase class
//
class InplaceTest : public CPPUNIT_NS::TestCase
{
  CPPUNIT_TEST_SUITE(InplaceTest);
  CPPUNIT_TEST(inplmrg1);
  CPPUNIT_TEST(inplmrg2);
  CPPUNIT_TEST_SUITE_END();

protected:
  void inplmrg1();
  void inplmrg2();
};

CPPUNIT_TEST_SUITE_REGISTRATION(InplaceTest);

//
// tests implementation
//
void InplaceTest::inplmrg1()
{
  int numbers[6] = { 1, 10, 42, 3, 16, 32 };
  inplace_merge(numbers, numbers + 3, numbers + 6);

  CPPUNIT_ASSERT(numbers[0]==1);
  CPPUNIT_ASSERT(numbers[1]==3);
  CPPUNIT_ASSERT(numbers[2]==10);
  CPPUNIT_ASSERT(numbers[3]==16);
  CPPUNIT_ASSERT(numbers[4]==32);
  CPPUNIT_ASSERT(numbers[5]==42);
}
void InplaceTest::inplmrg2()
{
  vector<size_t> v1(10);
  for(size_t i = 0; i < v1.size(); ++i)
    v1[i] =(v1.size() - i - 1) % 5;

  inplace_merge(v1.begin(), v1.begin() + 5, v1.end(), greater<size_t>());

  CPPUNIT_ASSERT(v1[0]==4);
  CPPUNIT_ASSERT(v1[1]==4);
  CPPUNIT_ASSERT(v1[2]==3);
  CPPUNIT_ASSERT(v1[3]==3);
  CPPUNIT_ASSERT(v1[4]==2);
  CPPUNIT_ASSERT(v1[5]==2);
  CPPUNIT_ASSERT(v1[6]==1);
  CPPUNIT_ASSERT(v1[7]==1);
  CPPUNIT_ASSERT(v1[8]==0);
  CPPUNIT_ASSERT(v1[9]==0);
}