3 #include <cds/opt/permutation.h>
4 #include "cppunit/cppunit_proxy.h"
8 class Permutations: public CppUnitMini::TestCase
10 static const size_t c_nMax = 1024;
12 template <typename Gen>
13 void test_with( Gen& gen, size_t nLen )
15 unsigned int arr[c_nMax];
16 for ( size_t nPass = 0; nPass < 10; ++nPass ) {
17 for ( size_t i = 0; i < c_nMax; ++i )
21 typename Gen::integer_type i = gen;
23 } while ( gen.next() );
25 for ( size_t i = 0; i < nLen; ++i )
26 CPPUNIT_CHECK_EX( arr[i] == 1, "arr[" << i << "]=" << arr[i] );
27 for ( size_t i = nLen; i < c_nMax; ++i )
28 CPPUNIT_CHECK_EX( arr[i] == 0, "arr[" << i << "]=" << arr[i] );
34 template <typename Gen>
37 for ( size_t nLen = 2; nLen <= c_nMax; ++nLen ) {
39 test_with( gen, nLen );
43 template <typename Gen>
46 for ( size_t nLen = 2; nLen <= c_nMax; nLen *= 2 ) {
48 test_with( gen, nLen );
52 void test_random_permutation()
54 test< cds::opt::v::random_permutation<> >();
57 void test_random2_permutation()
59 test2< cds::opt::v::random2_permutation<> >();
62 void test_random_shuffle_permutation()
64 test< cds::opt::v::random_shuffle_permutation<> >();
68 CPPUNIT_TEST_SUITE(Permutations)
69 CPPUNIT_TEST( test_random_permutation )
70 CPPUNIT_TEST( test_random2_permutation )
71 CPPUNIT_TEST( test_random_shuffle_permutation )
72 CPPUNIT_TEST_SUITE_END()
77 CPPUNIT_TEST_SUITE_REGISTRATION(misc::Permutations);