Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygensetdiff_test.cpp
Go to the documentation of this file.
00001 #include <numeric> 00002 #include <string> 00003 #include <iterator> 00004 #include <vector> 00005 #include <algorithm> 00006 #include <functional> 00007 00008 #include "iota.h" 00009 #include "cppunit/cppunit_proxy.h" 00010 00011 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00012 using namespace std; 00013 #endif 00014 00015 // 00016 // TestCase class 00017 // 00018 class SetDifferenceTest : public CPPUNIT_NS::TestCase 00019 { 00020 CPPUNIT_TEST_SUITE(SetDifferenceTest); 00021 CPPUNIT_TEST(setdiff0); 00022 CPPUNIT_TEST(setdiff1); 00023 CPPUNIT_TEST(setdiff2); 00024 CPPUNIT_TEST(setsymd0); 00025 CPPUNIT_TEST(setsymd1); 00026 CPPUNIT_TEST(setsymd2); 00027 CPPUNIT_TEST_SUITE_END(); 00028 00029 protected: 00030 void setdiff0(); 00031 void setdiff1(); 00032 void setdiff2(); 00033 void setsymd0(); 00034 void setsymd1(); 00035 void setsymd2(); 00036 }; 00037 00038 CPPUNIT_TEST_SUITE_REGISTRATION(SetDifferenceTest); 00039 00040 // 00041 // tests implementation 00042 // 00043 void SetDifferenceTest::setsymd0() 00044 { 00045 int v1[3] = { 13, 18, 23 }; 00046 int v2[4] = { 10, 13, 17, 23 }; 00047 int result[4] = { 0, 0, 0, 0 }; 00048 00049 set_symmetric_difference((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); 00050 CPPUNIT_ASSERT(result[0]==10); 00051 CPPUNIT_ASSERT(result[1]==17); 00052 CPPUNIT_ASSERT(result[2]==18); 00053 CPPUNIT_ASSERT(result[3]==0); 00054 } 00055 00056 void SetDifferenceTest::setsymd1() 00057 { 00058 vector<int> v1(10); 00059 __iota(v1.begin(), v1.end(), 0); 00060 vector<int> v2(10); 00061 __iota(v2.begin(), v2.end(), 7); 00062 00063 vector<int> diff; 00064 set_symmetric_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff)); 00065 CPPUNIT_ASSERT( diff.size() == 14 ); 00066 int int_res[] = {0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16}; 00067 for (int i = 0; i < 14; ++i) { 00068 CPPUNIT_ASSERT( diff[i] == int_res[i] ); 00069 } 00070 } 00071 00072 void SetDifferenceTest::setsymd2() 00073 { 00074 const char* word1 = "ABCDEFGHIJKLMNO"; 00075 const char* word2 = "LMNOPQRSTUVWXYZ"; 00076 00077 string diff; 00078 set_symmetric_difference(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), 00079 back_inserter(diff), less<char>()); 00080 CPPUNIT_ASSERT( diff.size() == 22 ); 00081 char char_res[] = "ABCDEFGHIJKPQRSTUVWXYZ"; 00082 for (int i = 0; i < 22; ++i) { 00083 CPPUNIT_ASSERT( diff[i] == char_res[i] ); 00084 } 00085 } 00086 00087 void SetDifferenceTest::setdiff0() 00088 { 00089 int v1[3] = { 13, 18, 23 }; 00090 int v2[4] = { 10, 13, 17, 23 }; 00091 int result[4] = { 0, 0, 0, 0 }; 00092 //18 0 0 0 00093 //10 17 23 0 00094 00095 set_difference((int*)v1, (int*)v1 + 3, (int*)v2, (int*)v2 + 4, (int*)result); 00096 CPPUNIT_ASSERT( result[0] == 18 ); 00097 CPPUNIT_ASSERT( result[1] == 0 ); 00098 CPPUNIT_ASSERT( result[2] == 0 ); 00099 CPPUNIT_ASSERT( result[3] == 0 ); 00100 00101 set_difference((int*)v2, (int*)v2 + 4, (int*)v1, (int*)v1 + 2, (int*)result); 00102 CPPUNIT_ASSERT( result[0] == 10 ); 00103 CPPUNIT_ASSERT( result[1] == 17 ); 00104 CPPUNIT_ASSERT( result[2] == 23 ); 00105 CPPUNIT_ASSERT( result[3] == 0 ); 00106 } 00107 00108 void SetDifferenceTest::setdiff1() 00109 { 00110 vector<int> v1(10); 00111 __iota(v1.begin(), v1.end(), 0); 00112 vector<int> v2(10); 00113 __iota(v2.begin(), v2.end(), 7); 00114 00115 vector<int> diff; 00116 set_difference(v1.begin(), v1.end(), v2.begin(), v2.end(), back_inserter(diff)); 00117 CPPUNIT_ASSERT( diff.size() == 7 ); 00118 for (int i = 0; i < 7; ++i) { 00119 CPPUNIT_ASSERT( diff[i] == i ); 00120 } 00121 } 00122 00123 void SetDifferenceTest::setdiff2() 00124 { 00125 const char* word1 = "ABCDEFGHIJKLMNO"; 00126 const char* word2 = "LMNOPQRSTUVWXYZ"; 00127 00128 string diff; 00129 set_difference(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), back_inserter(diff), less<char>()); 00130 CPPUNIT_ASSERT( diff.size() == 11 ); 00131 for (int i = 0; i < 11; ++i) { 00132 CPPUNIT_ASSERT( diff[i] == ('A' + i) ); 00133 } 00134 } Generated on Sun May 27 2012 04:35:47 for ReactOS by
1.7.6.1
|