sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "iota.h" sl@0: #include "cppunit/cppunit_proxy.h" sl@0: sl@0: #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) sl@0: using namespace std; sl@0: #endif sl@0: sl@0: // sl@0: // TestCase class sl@0: // sl@0: class SetIntersectionTest : public CPPUNIT_NS::TestCase sl@0: { sl@0: CPPUNIT_TEST_SUITE(SetIntersectionTest); sl@0: CPPUNIT_TEST(setintr0); sl@0: CPPUNIT_TEST(setintr1); sl@0: CPPUNIT_TEST(setintr2); sl@0: CPPUNIT_TEST_SUITE_END(); sl@0: sl@0: protected: sl@0: void setintr0(); sl@0: void setintr1(); sl@0: void setintr2(); sl@0: }; sl@0: sl@0: CPPUNIT_TEST_SUITE_REGISTRATION(SetIntersectionTest); sl@0: sl@0: // sl@0: // tests implementation sl@0: // sl@0: void SetIntersectionTest::setintr0() sl@0: { sl@0: int v1[3] = { 13, 18, 23 }; sl@0: int v2[4] = { 10, 13, 17, 23 }; sl@0: int result[4] = { 0, 0, 0, 0 }; sl@0: sl@0: set_intersection((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); sl@0: sl@0: CPPUNIT_ASSERT(result[0]==13); sl@0: CPPUNIT_ASSERT(result[1]==23); sl@0: CPPUNIT_ASSERT(result[2]==0); sl@0: CPPUNIT_ASSERT(result[3]==0); sl@0: } sl@0: sl@0: void SetIntersectionTest::setintr1() sl@0: { sl@0: vector v1(10); sl@0: __iota(v1.begin(), v1.end(), 0); sl@0: vector v2(10); sl@0: __iota(v2.begin(), v2.end(), 7); sl@0: sl@0: vector inter; sl@0: set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(inter)); sl@0: CPPUNIT_ASSERT( inter.size() == 3 ); sl@0: CPPUNIT_ASSERT( inter[0] == 7 ); sl@0: CPPUNIT_ASSERT( inter[1] == 8 ); sl@0: CPPUNIT_ASSERT( inter[2] == 9 ); sl@0: } sl@0: sl@0: void SetIntersectionTest::setintr2() sl@0: { sl@0: char* word1 = "ABCDEFGHIJKLMNO"; sl@0: char* word2 = "LMNOPQRSTUVWXYZ"; sl@0: sl@0: string inter; sl@0: set_intersection(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), sl@0: back_inserter(inter), less()); sl@0: CPPUNIT_ASSERT( inter.size() == 4 ); sl@0: CPPUNIT_ASSERT( inter[0] == 'L' ); sl@0: CPPUNIT_ASSERT( inter[1] == 'M' ); sl@0: CPPUNIT_ASSERT( inter[2] == 'N' ); sl@0: CPPUNIT_ASSERT( inter[3] == 'O' ); sl@0: }