Update contrib.
7 #include "cppunit/cppunit_proxy.h"
9 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
16 class MergeTest : public CPPUNIT_NS::TestCase
18 CPPUNIT_TEST_SUITE(MergeTest);
22 CPPUNIT_TEST_SUITE_END();
30 CPPUNIT_TEST_SUITE_REGISTRATION(MergeTest);
33 // tests implementation
35 void MergeTest::merge0()
37 int numbers1[5] = { 1, 6, 13, 25, 101 };
38 int numbers2[5] = {-5, 26, 36, 46, 99 };
41 merge((int*)numbers1, (int*)numbers1 + 5, (int*)numbers2, (int*)numbers2 + 5, (int*)result);
43 CPPUNIT_ASSERT(result[0]==-5);
44 CPPUNIT_ASSERT(result[1]==1);
45 CPPUNIT_ASSERT(result[2]==6);
46 CPPUNIT_ASSERT(result[3]==13);
47 CPPUNIT_ASSERT(result[4]==25);
48 CPPUNIT_ASSERT(result[5]==26);
49 CPPUNIT_ASSERT(result[6]==36);
50 CPPUNIT_ASSERT(result[7]==46);
51 CPPUNIT_ASSERT(result[8]==99);
52 CPPUNIT_ASSERT(result[9]==101);
54 void MergeTest::merge1()
57 vector<int> v2(v1.size());
58 __iota(v1.begin(), v1.end(), 0);
59 __iota(v2.begin(), v2.end(), 3);
61 vector <int> result(v1.size() + v2.size());
62 merge(v1.begin(), v1.end(), v2.begin(), v2.end(), result.begin());
64 CPPUNIT_ASSERT(result[0]==0);
65 CPPUNIT_ASSERT(result[1]==1);
66 CPPUNIT_ASSERT(result[2]==2);
67 CPPUNIT_ASSERT(result[3]==3);
68 CPPUNIT_ASSERT(result[4]==3);
69 CPPUNIT_ASSERT(result[5]==4);
70 CPPUNIT_ASSERT(result[6]==4);
71 CPPUNIT_ASSERT(result[7]==5);
72 CPPUNIT_ASSERT(result[8]==6);
73 CPPUNIT_ASSERT(result[9]==7);
76 void MergeTest::merge2()
79 vector <int> v2(v1.size());
80 for (int i = 0; (size_t)i < v1.size(); ++i) {
84 vector<int> result(v1.size() + v2.size());
85 merge(v1.begin(), v1.end(), v2.begin(), v2.end(), result.begin(), greater<int>() );
87 CPPUNIT_ASSERT(result[0]==10);
88 CPPUNIT_ASSERT(result[1]==9);
89 CPPUNIT_ASSERT(result[2]==8);
90 CPPUNIT_ASSERT(result[3]==7);
91 CPPUNIT_ASSERT(result[4]==7);
92 CPPUNIT_ASSERT(result[5]==6);
93 CPPUNIT_ASSERT(result[6]==6);
94 CPPUNIT_ASSERT(result[7]==5);
95 CPPUNIT_ASSERT(result[8]==4);
96 CPPUNIT_ASSERT(result[9]==3);