os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/perm_test.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/genericopenlibs/cppstdlib/stl/test/unit/perm_test.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,228 @@
     1.4 +#include <vector>
     1.5 +#include <algorithm>
     1.6 +#include <numeric>
     1.7 +#include <iterator>
     1.8 +#include <functional>
     1.9 +
    1.10 +#include "iota.h"
    1.11 +#include "cppunit/cppunit_proxy.h"
    1.12 +
    1.13 +#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
    1.14 +using namespace std;
    1.15 +#endif
    1.16 +
    1.17 +//
    1.18 +// TestCase class
    1.19 +//
    1.20 +class PermTest : public CPPUNIT_NS::TestCase
    1.21 +{
    1.22 +  CPPUNIT_TEST_SUITE(PermTest);
    1.23 +  CPPUNIT_TEST(nextprm0);
    1.24 +  CPPUNIT_TEST(nextprm1);
    1.25 +  CPPUNIT_TEST(nextprm2);
    1.26 +  CPPUNIT_TEST(prevprm0);
    1.27 +  CPPUNIT_TEST(prevprm1);
    1.28 +  CPPUNIT_TEST(prevprm2);
    1.29 +  CPPUNIT_TEST_SUITE_END();
    1.30 +
    1.31 +protected:
    1.32 +  void nextprm0();
    1.33 +  void nextprm1();
    1.34 +  void nextprm2();
    1.35 +  void prevprm0();
    1.36 +  void prevprm1();
    1.37 +  void prevprm2();
    1.38 +};
    1.39 +
    1.40 +CPPUNIT_TEST_SUITE_REGISTRATION(PermTest);
    1.41 +
    1.42 +//
    1.43 +// tests implementation
    1.44 +//
    1.45 +void PermTest::prevprm0()
    1.46 +{
    1.47 +  int v1[3] = { 0, 1, 2 };
    1.48 +  prev_permutation(v1, v1 + 3);
    1.49 +
    1.50 +  CPPUNIT_ASSERT(v1[0]==2);
    1.51 +  CPPUNIT_ASSERT(v1[1]==1);
    1.52 +  CPPUNIT_ASSERT(v1[2]==0);
    1.53 +}
    1.54 +void PermTest::prevprm1()
    1.55 +{
    1.56 +  vector <int> v1(3);
    1.57 +  __iota(v1.begin(), v1.end(), 0);
    1.58 +
    1.59 +  prev_permutation(v1.begin(), v1.end());
    1.60 +  CPPUNIT_ASSERT(v1[0]==2);
    1.61 +  CPPUNIT_ASSERT(v1[1]==1);
    1.62 +  CPPUNIT_ASSERT(v1[2]==0);
    1.63 +  prev_permutation(v1.begin(), v1.end());
    1.64 +  CPPUNIT_ASSERT(v1[0]==2);
    1.65 +  CPPUNIT_ASSERT(v1[1]==0);
    1.66 +  CPPUNIT_ASSERT(v1[2]==1);
    1.67 +  prev_permutation(v1.begin(), v1.end());
    1.68 +  CPPUNIT_ASSERT(v1[0]==1);
    1.69 +  CPPUNIT_ASSERT(v1[1]==2);
    1.70 +  CPPUNIT_ASSERT(v1[2]==0);
    1.71 +  prev_permutation(v1.begin(), v1.end());
    1.72 +  CPPUNIT_ASSERT(v1[0]==1);
    1.73 +  CPPUNIT_ASSERT(v1[1]==0);
    1.74 +  CPPUNIT_ASSERT(v1[2]==2);
    1.75 +  prev_permutation(v1.begin(), v1.end());
    1.76 +  CPPUNIT_ASSERT(v1[0]==0);
    1.77 +  CPPUNIT_ASSERT(v1[1]==2);//
    1.78 +  CPPUNIT_ASSERT(v1[2]==1);
    1.79 +  prev_permutation(v1.begin(), v1.end());
    1.80 +  CPPUNIT_ASSERT(v1[0]==0);
    1.81 +  CPPUNIT_ASSERT(v1[1]==1);
    1.82 +  CPPUNIT_ASSERT(v1[2]==2);
    1.83 +  prev_permutation(v1.begin(), v1.end());
    1.84 +  CPPUNIT_ASSERT(v1[0]==2);
    1.85 +  CPPUNIT_ASSERT(v1[1]==1);
    1.86 +  CPPUNIT_ASSERT(v1[2]==0);
    1.87 +  prev_permutation(v1.begin(), v1.end());
    1.88 +  CPPUNIT_ASSERT(v1[0]==2);
    1.89 +  CPPUNIT_ASSERT(v1[1]==0);
    1.90 +  CPPUNIT_ASSERT(v1[2]==1);
    1.91 +  prev_permutation(v1.begin(), v1.end());
    1.92 +  CPPUNIT_ASSERT(v1[0]==1);
    1.93 +  CPPUNIT_ASSERT(v1[1]==2);
    1.94 +  CPPUNIT_ASSERT(v1[2]==0);
    1.95 +}
    1.96 +void PermTest::prevprm2()
    1.97 +{
    1.98 +  vector <int> v1(3);
    1.99 +  __iota(v1.begin(), v1.end(), 0);
   1.100 +
   1.101 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.102 +  CPPUNIT_ASSERT(v1[0]==0);
   1.103 +  CPPUNIT_ASSERT(v1[1]==2);
   1.104 +  CPPUNIT_ASSERT(v1[2]==1);
   1.105 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.106 +  CPPUNIT_ASSERT(v1[0]==1);
   1.107 +  CPPUNIT_ASSERT(v1[1]==0);
   1.108 +  CPPUNIT_ASSERT(v1[2]==2);
   1.109 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.110 +  CPPUNIT_ASSERT(v1[0]==1);
   1.111 +  CPPUNIT_ASSERT(v1[1]==2);
   1.112 +  CPPUNIT_ASSERT(v1[2]==0);
   1.113 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.114 +  CPPUNIT_ASSERT(v1[0]==2);
   1.115 +  CPPUNIT_ASSERT(v1[1]==0);
   1.116 +  CPPUNIT_ASSERT(v1[2]==1);
   1.117 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.118 +  CPPUNIT_ASSERT(v1[0]==2);
   1.119 +  CPPUNIT_ASSERT(v1[1]==1);
   1.120 +  CPPUNIT_ASSERT(v1[2]==0);
   1.121 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.122 +  CPPUNIT_ASSERT(v1[0]==0);
   1.123 +  CPPUNIT_ASSERT(v1[1]==1);
   1.124 +  CPPUNIT_ASSERT(v1[2]==2);
   1.125 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.126 +  CPPUNIT_ASSERT(v1[0]==0);
   1.127 +  CPPUNIT_ASSERT(v1[1]==2);
   1.128 +  CPPUNIT_ASSERT(v1[2]==1);
   1.129 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.130 +  CPPUNIT_ASSERT(v1[0]==1);
   1.131 +  CPPUNIT_ASSERT(v1[1]==0);
   1.132 +  CPPUNIT_ASSERT(v1[2]==2);
   1.133 +  prev_permutation(v1.begin(), v1.end(), greater<int>());
   1.134 +  CPPUNIT_ASSERT(v1[0]==1);
   1.135 +  CPPUNIT_ASSERT(v1[1]==2);
   1.136 +  CPPUNIT_ASSERT(v1[2]==0);
   1.137 +}
   1.138 +void PermTest::nextprm0()
   1.139 +{
   1.140 +  int v1[3] = { 0, 1, 2 };
   1.141 +  next_permutation(v1, v1 + 3);
   1.142 +
   1.143 +  CPPUNIT_ASSERT(v1[0]==0);
   1.144 +  CPPUNIT_ASSERT(v1[1]==2);
   1.145 +  CPPUNIT_ASSERT(v1[2]==1);
   1.146 +}
   1.147 +void PermTest::nextprm1()
   1.148 +{
   1.149 +  vector <int> v1(3);
   1.150 +  __iota(v1.begin(), v1.end(), 0);
   1.151 +
   1.152 +  next_permutation(v1.begin(), v1.end());
   1.153 +  CPPUNIT_ASSERT(v1[0]==0);
   1.154 +  CPPUNIT_ASSERT(v1[1]==2);
   1.155 +  CPPUNIT_ASSERT(v1[2]==1);
   1.156 +  next_permutation(v1.begin(), v1.end());
   1.157 +  CPPUNIT_ASSERT(v1[0]==1);
   1.158 +  CPPUNIT_ASSERT(v1[1]==0);
   1.159 +  CPPUNIT_ASSERT(v1[2]==2);
   1.160 +  next_permutation(v1.begin(), v1.end());
   1.161 +  CPPUNIT_ASSERT(v1[0]==1);
   1.162 +  CPPUNIT_ASSERT(v1[1]==2);
   1.163 +  CPPUNIT_ASSERT(v1[2]==0);
   1.164 +  next_permutation(v1.begin(), v1.end());
   1.165 +  CPPUNIT_ASSERT(v1[0]==2);
   1.166 +  CPPUNIT_ASSERT(v1[1]==0);
   1.167 +  CPPUNIT_ASSERT(v1[2]==1);
   1.168 +  next_permutation(v1.begin(), v1.end());
   1.169 +  CPPUNIT_ASSERT(v1[0]==2);
   1.170 +  CPPUNIT_ASSERT(v1[1]==1);
   1.171 +  CPPUNIT_ASSERT(v1[2]==0);
   1.172 +  next_permutation(v1.begin(), v1.end());
   1.173 +  CPPUNIT_ASSERT(v1[0]==0);
   1.174 +  CPPUNIT_ASSERT(v1[1]==1);
   1.175 +  CPPUNIT_ASSERT(v1[2]==2);
   1.176 +  next_permutation(v1.begin(), v1.end());
   1.177 +  CPPUNIT_ASSERT(v1[0]==0);
   1.178 +  CPPUNIT_ASSERT(v1[1]==2);
   1.179 +  CPPUNIT_ASSERT(v1[2]==1);
   1.180 +  next_permutation(v1.begin(), v1.end());
   1.181 +  CPPUNIT_ASSERT(v1[0]==1);
   1.182 +  CPPUNIT_ASSERT(v1[1]==0);
   1.183 +  CPPUNIT_ASSERT(v1[2]==2);
   1.184 +  next_permutation(v1.begin(), v1.end());
   1.185 +  CPPUNIT_ASSERT(v1[0]==1);
   1.186 +  CPPUNIT_ASSERT(v1[1]==2);
   1.187 +  CPPUNIT_ASSERT(v1[2]==0);
   1.188 +}
   1.189 +void PermTest::nextprm2()
   1.190 +{
   1.191 +  vector <char> v1(3);
   1.192 +  __iota(v1.begin(), v1.end(), 'A');
   1.193 +
   1.194 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.195 +  CPPUNIT_ASSERT(v1[0]=='A');
   1.196 +  CPPUNIT_ASSERT(v1[1]=='C');
   1.197 +  CPPUNIT_ASSERT(v1[2]=='B');
   1.198 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.199 +  CPPUNIT_ASSERT(v1[0]=='B');
   1.200 +  CPPUNIT_ASSERT(v1[1]=='A');
   1.201 +  CPPUNIT_ASSERT(v1[2]=='C');
   1.202 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.203 +  CPPUNIT_ASSERT(v1[0]=='B');
   1.204 +  CPPUNIT_ASSERT(v1[1]=='C');
   1.205 +  CPPUNIT_ASSERT(v1[2]=='A');
   1.206 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.207 +  CPPUNIT_ASSERT(v1[0]=='C');
   1.208 +  CPPUNIT_ASSERT(v1[1]=='A');
   1.209 +  CPPUNIT_ASSERT(v1[2]=='B');
   1.210 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.211 +  CPPUNIT_ASSERT(v1[0]=='C');
   1.212 +  CPPUNIT_ASSERT(v1[1]=='B');
   1.213 +  CPPUNIT_ASSERT(v1[2]=='A');
   1.214 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.215 +  CPPUNIT_ASSERT(v1[0]=='A');
   1.216 +  CPPUNIT_ASSERT(v1[1]=='B');
   1.217 +  CPPUNIT_ASSERT(v1[2]=='C');
   1.218 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.219 +  CPPUNIT_ASSERT(v1[0]=='A');
   1.220 +  CPPUNIT_ASSERT(v1[1]=='C');
   1.221 +  CPPUNIT_ASSERT(v1[2]=='B');
   1.222 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.223 +  CPPUNIT_ASSERT(v1[0]=='B');
   1.224 +  CPPUNIT_ASSERT(v1[1]=='A');
   1.225 +  CPPUNIT_ASSERT(v1[2]=='C');
   1.226 +  next_permutation(v1.begin(), v1.end(), less<char>());
   1.227 +  CPPUNIT_ASSERT(v1[0]=='B');
   1.228 +  CPPUNIT_ASSERT(v1[1]=='C');
   1.229 +  CPPUNIT_ASSERT(v1[2]=='A');
   1.230 +
   1.231 +}