Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenperm_test.cpp
Go to the documentation of this file.
00001 #include <vector> 00002 #include <algorithm> 00003 #include <numeric> 00004 #include <iterator> 00005 #include <functional> 00006 00007 #include "iota.h" 00008 #include "cppunit/cppunit_proxy.h" 00009 00010 #if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES) 00011 using namespace std; 00012 #endif 00013 00014 // 00015 // TestCase class 00016 // 00017 class PermTest : public CPPUNIT_NS::TestCase 00018 { 00019 CPPUNIT_TEST_SUITE(PermTest); 00020 CPPUNIT_TEST(nextprm0); 00021 CPPUNIT_TEST(nextprm1); 00022 CPPUNIT_TEST(nextprm2); 00023 CPPUNIT_TEST(prevprm0); 00024 CPPUNIT_TEST(prevprm1); 00025 CPPUNIT_TEST(prevprm2); 00026 CPPUNIT_TEST_SUITE_END(); 00027 00028 protected: 00029 void nextprm0(); 00030 void nextprm1(); 00031 void nextprm2(); 00032 void prevprm0(); 00033 void prevprm1(); 00034 void prevprm2(); 00035 }; 00036 00037 CPPUNIT_TEST_SUITE_REGISTRATION(PermTest); 00038 00039 // 00040 // tests implementation 00041 // 00042 void PermTest::prevprm0() 00043 { 00044 int v1[3] = { 0, 1, 2 }; 00045 prev_permutation(v1, v1 + 3); 00046 00047 CPPUNIT_ASSERT(v1[0]==2); 00048 CPPUNIT_ASSERT(v1[1]==1); 00049 CPPUNIT_ASSERT(v1[2]==0); 00050 } 00051 void PermTest::prevprm1() 00052 { 00053 vector <int> v1(3); 00054 __iota(v1.begin(), v1.end(), 0); 00055 00056 prev_permutation(v1.begin(), v1.end()); 00057 CPPUNIT_ASSERT(v1[0]==2); 00058 CPPUNIT_ASSERT(v1[1]==1); 00059 CPPUNIT_ASSERT(v1[2]==0); 00060 prev_permutation(v1.begin(), v1.end()); 00061 CPPUNIT_ASSERT(v1[0]==2); 00062 CPPUNIT_ASSERT(v1[1]==0); 00063 CPPUNIT_ASSERT(v1[2]==1); 00064 prev_permutation(v1.begin(), v1.end()); 00065 CPPUNIT_ASSERT(v1[0]==1); 00066 CPPUNIT_ASSERT(v1[1]==2); 00067 CPPUNIT_ASSERT(v1[2]==0); 00068 prev_permutation(v1.begin(), v1.end()); 00069 CPPUNIT_ASSERT(v1[0]==1); 00070 CPPUNIT_ASSERT(v1[1]==0); 00071 CPPUNIT_ASSERT(v1[2]==2); 00072 prev_permutation(v1.begin(), v1.end()); 00073 CPPUNIT_ASSERT(v1[0]==0); 00074 CPPUNIT_ASSERT(v1[1]==2);// 00075 CPPUNIT_ASSERT(v1[2]==1); 00076 prev_permutation(v1.begin(), v1.end()); 00077 CPPUNIT_ASSERT(v1[0]==0); 00078 CPPUNIT_ASSERT(v1[1]==1); 00079 CPPUNIT_ASSERT(v1[2]==2); 00080 prev_permutation(v1.begin(), v1.end()); 00081 CPPUNIT_ASSERT(v1[0]==2); 00082 CPPUNIT_ASSERT(v1[1]==1); 00083 CPPUNIT_ASSERT(v1[2]==0); 00084 prev_permutation(v1.begin(), v1.end()); 00085 CPPUNIT_ASSERT(v1[0]==2); 00086 CPPUNIT_ASSERT(v1[1]==0); 00087 CPPUNIT_ASSERT(v1[2]==1); 00088 prev_permutation(v1.begin(), v1.end()); 00089 CPPUNIT_ASSERT(v1[0]==1); 00090 CPPUNIT_ASSERT(v1[1]==2); 00091 CPPUNIT_ASSERT(v1[2]==0); 00092 } 00093 void PermTest::prevprm2() 00094 { 00095 vector <int> v1(3); 00096 __iota(v1.begin(), v1.end(), 0); 00097 00098 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00099 CPPUNIT_ASSERT(v1[0]==0); 00100 CPPUNIT_ASSERT(v1[1]==2); 00101 CPPUNIT_ASSERT(v1[2]==1); 00102 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00103 CPPUNIT_ASSERT(v1[0]==1); 00104 CPPUNIT_ASSERT(v1[1]==0); 00105 CPPUNIT_ASSERT(v1[2]==2); 00106 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00107 CPPUNIT_ASSERT(v1[0]==1); 00108 CPPUNIT_ASSERT(v1[1]==2); 00109 CPPUNIT_ASSERT(v1[2]==0); 00110 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00111 CPPUNIT_ASSERT(v1[0]==2); 00112 CPPUNIT_ASSERT(v1[1]==0); 00113 CPPUNIT_ASSERT(v1[2]==1); 00114 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00115 CPPUNIT_ASSERT(v1[0]==2); 00116 CPPUNIT_ASSERT(v1[1]==1); 00117 CPPUNIT_ASSERT(v1[2]==0); 00118 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00119 CPPUNIT_ASSERT(v1[0]==0); 00120 CPPUNIT_ASSERT(v1[1]==1); 00121 CPPUNIT_ASSERT(v1[2]==2); 00122 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00123 CPPUNIT_ASSERT(v1[0]==0); 00124 CPPUNIT_ASSERT(v1[1]==2); 00125 CPPUNIT_ASSERT(v1[2]==1); 00126 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00127 CPPUNIT_ASSERT(v1[0]==1); 00128 CPPUNIT_ASSERT(v1[1]==0); 00129 CPPUNIT_ASSERT(v1[2]==2); 00130 prev_permutation(v1.begin(), v1.end(), greater<int>()); 00131 CPPUNIT_ASSERT(v1[0]==1); 00132 CPPUNIT_ASSERT(v1[1]==2); 00133 CPPUNIT_ASSERT(v1[2]==0); 00134 } 00135 void PermTest::nextprm0() 00136 { 00137 int v1[3] = { 0, 1, 2 }; 00138 next_permutation(v1, v1 + 3); 00139 00140 CPPUNIT_ASSERT(v1[0]==0); 00141 CPPUNIT_ASSERT(v1[1]==2); 00142 CPPUNIT_ASSERT(v1[2]==1); 00143 } 00144 void PermTest::nextprm1() 00145 { 00146 vector <int> v1(3); 00147 __iota(v1.begin(), v1.end(), 0); 00148 00149 next_permutation(v1.begin(), v1.end()); 00150 CPPUNIT_ASSERT(v1[0]==0); 00151 CPPUNIT_ASSERT(v1[1]==2); 00152 CPPUNIT_ASSERT(v1[2]==1); 00153 next_permutation(v1.begin(), v1.end()); 00154 CPPUNIT_ASSERT(v1[0]==1); 00155 CPPUNIT_ASSERT(v1[1]==0); 00156 CPPUNIT_ASSERT(v1[2]==2); 00157 next_permutation(v1.begin(), v1.end()); 00158 CPPUNIT_ASSERT(v1[0]==1); 00159 CPPUNIT_ASSERT(v1[1]==2); 00160 CPPUNIT_ASSERT(v1[2]==0); 00161 next_permutation(v1.begin(), v1.end()); 00162 CPPUNIT_ASSERT(v1[0]==2); 00163 CPPUNIT_ASSERT(v1[1]==0); 00164 CPPUNIT_ASSERT(v1[2]==1); 00165 next_permutation(v1.begin(), v1.end()); 00166 CPPUNIT_ASSERT(v1[0]==2); 00167 CPPUNIT_ASSERT(v1[1]==1); 00168 CPPUNIT_ASSERT(v1[2]==0); 00169 next_permutation(v1.begin(), v1.end()); 00170 CPPUNIT_ASSERT(v1[0]==0); 00171 CPPUNIT_ASSERT(v1[1]==1); 00172 CPPUNIT_ASSERT(v1[2]==2); 00173 next_permutation(v1.begin(), v1.end()); 00174 CPPUNIT_ASSERT(v1[0]==0); 00175 CPPUNIT_ASSERT(v1[1]==2); 00176 CPPUNIT_ASSERT(v1[2]==1); 00177 next_permutation(v1.begin(), v1.end()); 00178 CPPUNIT_ASSERT(v1[0]==1); 00179 CPPUNIT_ASSERT(v1[1]==0); 00180 CPPUNIT_ASSERT(v1[2]==2); 00181 next_permutation(v1.begin(), v1.end()); 00182 CPPUNIT_ASSERT(v1[0]==1); 00183 CPPUNIT_ASSERT(v1[1]==2); 00184 CPPUNIT_ASSERT(v1[2]==0); 00185 } 00186 void PermTest::nextprm2() 00187 { 00188 vector <char> v1(3); 00189 __iota(v1.begin(), v1.end(), 'A'); 00190 00191 next_permutation(v1.begin(), v1.end(), less<char>()); 00192 CPPUNIT_ASSERT(v1[0]=='A'); 00193 CPPUNIT_ASSERT(v1[1]=='C'); 00194 CPPUNIT_ASSERT(v1[2]=='B'); 00195 next_permutation(v1.begin(), v1.end(), less<char>()); 00196 CPPUNIT_ASSERT(v1[0]=='B'); 00197 CPPUNIT_ASSERT(v1[1]=='A'); 00198 CPPUNIT_ASSERT(v1[2]=='C'); 00199 next_permutation(v1.begin(), v1.end(), less<char>()); 00200 CPPUNIT_ASSERT(v1[0]=='B'); 00201 CPPUNIT_ASSERT(v1[1]=='C'); 00202 CPPUNIT_ASSERT(v1[2]=='A'); 00203 next_permutation(v1.begin(), v1.end(), less<char>()); 00204 CPPUNIT_ASSERT(v1[0]=='C'); 00205 CPPUNIT_ASSERT(v1[1]=='A'); 00206 CPPUNIT_ASSERT(v1[2]=='B'); 00207 next_permutation(v1.begin(), v1.end(), less<char>()); 00208 CPPUNIT_ASSERT(v1[0]=='C'); 00209 CPPUNIT_ASSERT(v1[1]=='B'); 00210 CPPUNIT_ASSERT(v1[2]=='A'); 00211 next_permutation(v1.begin(), v1.end(), less<char>()); 00212 CPPUNIT_ASSERT(v1[0]=='A'); 00213 CPPUNIT_ASSERT(v1[1]=='B'); 00214 CPPUNIT_ASSERT(v1[2]=='C'); 00215 next_permutation(v1.begin(), v1.end(), less<char>()); 00216 CPPUNIT_ASSERT(v1[0]=='A'); 00217 CPPUNIT_ASSERT(v1[1]=='C'); 00218 CPPUNIT_ASSERT(v1[2]=='B'); 00219 next_permutation(v1.begin(), v1.end(), less<char>()); 00220 CPPUNIT_ASSERT(v1[0]=='B'); 00221 CPPUNIT_ASSERT(v1[1]=='A'); 00222 CPPUNIT_ASSERT(v1[2]=='C'); 00223 next_permutation(v1.begin(), v1.end(), less<char>()); 00224 CPPUNIT_ASSERT(v1[0]=='B'); 00225 CPPUNIT_ASSERT(v1[1]=='C'); 00226 CPPUNIT_ASSERT(v1[2]=='A'); 00227 00228 } Generated on Sun May 27 2012 04:35:39 for ReactOS by
1.7.6.1
|