9 #include "cppunit/cppunit_proxy.h"
11 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
18 class SetDifferenceTest
: public CPPUNIT_NS::TestCase
20 CPPUNIT_TEST_SUITE(SetDifferenceTest
);
21 CPPUNIT_TEST(setdiff0
);
22 CPPUNIT_TEST(setdiff1
);
23 CPPUNIT_TEST(setdiff2
);
24 CPPUNIT_TEST(setsymd0
);
25 CPPUNIT_TEST(setsymd1
);
26 CPPUNIT_TEST(setsymd2
);
27 CPPUNIT_TEST_SUITE_END();
38 CPPUNIT_TEST_SUITE_REGISTRATION(SetDifferenceTest
);
41 // tests implementation
43 void SetDifferenceTest::setsymd0()
45 int v1
[3] = { 13, 18, 23 };
46 int v2
[4] = { 10, 13, 17, 23 };
47 int result
[4] = { 0, 0, 0, 0 };
49 set_symmetric_difference((int*)v1
, (int*)v1
+ 3, (int*)v2
, (int*)v2
+ 4, (int*)result
);
50 CPPUNIT_ASSERT(result
[0]==10);
51 CPPUNIT_ASSERT(result
[1]==17);
52 CPPUNIT_ASSERT(result
[2]==18);
53 CPPUNIT_ASSERT(result
[3]==0);
56 void SetDifferenceTest::setsymd1()
59 __iota(v1
.begin(), v1
.end(), 0);
61 __iota(v2
.begin(), v2
.end(), 7);
64 set_symmetric_difference(v1
.begin(), v1
.end(), v2
.begin(), v2
.end(), back_inserter(diff
));
65 CPPUNIT_ASSERT( diff
.size() == 14 );
66 int int_res
[] = {0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16};
67 for (int i
= 0; i
< 14; ++i
) {
68 CPPUNIT_ASSERT( diff
[i
] == int_res
[i
] );
72 void SetDifferenceTest::setsymd2()
74 const char* word1
= "ABCDEFGHIJKLMNO";
75 const char* word2
= "LMNOPQRSTUVWXYZ";
78 set_symmetric_difference(word1
, word1
+ ::strlen(word1
), word2
, word2
+ ::strlen(word2
),
79 back_inserter(diff
), less
<char>());
80 CPPUNIT_ASSERT( diff
.size() == 22 );
81 char char_res
[] = "ABCDEFGHIJKPQRSTUVWXYZ";
82 for (int i
= 0; i
< 22; ++i
) {
83 CPPUNIT_ASSERT( diff
[i
] == char_res
[i
] );
87 void SetDifferenceTest::setdiff0()
89 int v1
[3] = { 13, 18, 23 };
90 int v2
[4] = { 10, 13, 17, 23 };
91 int result
[4] = { 0, 0, 0, 0 };
95 set_difference((int*)v1
, (int*)v1
+ 3, (int*)v2
, (int*)v2
+ 4, (int*)result
);
96 CPPUNIT_ASSERT( result
[0] == 18 );
97 CPPUNIT_ASSERT( result
[1] == 0 );
98 CPPUNIT_ASSERT( result
[2] == 0 );
99 CPPUNIT_ASSERT( result
[3] == 0 );
101 set_difference((int*)v2
, (int*)v2
+ 4, (int*)v1
, (int*)v1
+ 2, (int*)result
);
102 CPPUNIT_ASSERT( result
[0] == 10 );
103 CPPUNIT_ASSERT( result
[1] == 17 );
104 CPPUNIT_ASSERT( result
[2] == 23 );
105 CPPUNIT_ASSERT( result
[3] == 0 );
108 void SetDifferenceTest::setdiff1()
111 __iota(v1
.begin(), v1
.end(), 0);
113 __iota(v2
.begin(), v2
.end(), 7);
116 set_difference(v1
.begin(), v1
.end(), v2
.begin(), v2
.end(), back_inserter(diff
));
117 CPPUNIT_ASSERT( diff
.size() == 7 );
118 for (int i
= 0; i
< 7; ++i
) {
119 CPPUNIT_ASSERT( diff
[i
] == i
);
123 void SetDifferenceTest::setdiff2()
125 const char* word1
= "ABCDEFGHIJKLMNO";
126 const char* word2
= "LMNOPQRSTUVWXYZ";
129 set_difference(word1
, word1
+ ::strlen(word1
), word2
, word2
+ ::strlen(word2
), back_inserter(diff
), less
<char>());
130 CPPUNIT_ASSERT( diff
.size() == 11 );
131 for (int i
= 0; i
< 11; ++i
) {
132 CPPUNIT_ASSERT( diff
[i
] == ('A' + i
) );