1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/setunion_test.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,81 @@
1.4 +#include <numeric>
1.5 +#include <string>
1.6 +#include <iterator>
1.7 +#include <vector>
1.8 +#include <algorithm>
1.9 +#include <functional>
1.10 +
1.11 +#include "iota.h"
1.12 +#include "cppunit/cppunit_proxy.h"
1.13 +
1.14 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
1.15 +using namespace std;
1.16 +#endif
1.17 +
1.18 +//
1.19 +// TestCase class
1.20 +//
1.21 +class SetUnionTest : public CPPUNIT_NS::TestCase
1.22 +{
1.23 + CPPUNIT_TEST_SUITE(SetUnionTest);
1.24 + CPPUNIT_TEST(setunon0);
1.25 + CPPUNIT_TEST(setunon1);
1.26 + CPPUNIT_TEST(setunon2);
1.27 + CPPUNIT_TEST_SUITE_END();
1.28 +
1.29 +protected:
1.30 + void setunon0();
1.31 + void setunon1();
1.32 + void setunon2();
1.33 +};
1.34 +
1.35 +CPPUNIT_TEST_SUITE_REGISTRATION(SetUnionTest);
1.36 +
1.37 +//
1.38 +// tests implementation
1.39 +//
1.40 +void SetUnionTest::setunon0()
1.41 +{
1.42 + int v1[3] = { 13, 18, 23 };
1.43 + int v2[4] = { 10, 13, 17, 23 };
1.44 + int result[7] = { 0, 0, 0, 0, 0, 0, 0 };
1.45 +
1.46 + set_union((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result);
1.47 +
1.48 + CPPUNIT_ASSERT(result[0]==10);
1.49 + CPPUNIT_ASSERT(result[1]==13);
1.50 + CPPUNIT_ASSERT(result[2]==17);
1.51 + CPPUNIT_ASSERT(result[3]==18);
1.52 + CPPUNIT_ASSERT(result[4]==23);
1.53 + CPPUNIT_ASSERT(result[5]==0);
1.54 + CPPUNIT_ASSERT(result[6]==0);
1.55 +}
1.56 +
1.57 +void SetUnionTest::setunon1()
1.58 +{
1.59 + vector <int> v1(10);
1.60 + __iota(v1.begin(), v1.end(), 0);
1.61 + vector <int> v2(10);
1.62 + __iota(v2.begin(), v2.end(), 7);
1.63 +
1.64 + vector<int> diff;
1.65 + set_union(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff));
1.66 + CPPUNIT_ASSERT( diff.size() == 17 );
1.67 + for (int i = 0; i < 17; ++i) {
1.68 + CPPUNIT_ASSERT( diff[i] == i );
1.69 + }
1.70 +}
1.71 +
1.72 +void SetUnionTest::setunon2()
1.73 +{
1.74 + char* word1 = "ABCDEFGHIJKLMNO";
1.75 + char* word2 = "LMNOPQRSTUVWXYZ";
1.76 +
1.77 + string diff;
1.78 + set_union(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2),
1.79 + back_inserter(diff), less<char>());
1.80 + CPPUNIT_ASSERT( diff.size() == 26 );
1.81 + for (int i = 0; i < 26; ++i) {
1.82 + CPPUNIT_ASSERT( diff[i] == ('A' + i) );
1.83 + }
1.84 +}