~blep/cppunit2/cpptl-integration

« back to all changes in this revision

Viewing changes to test/unittest_cpptl/shellsorttest.cpp

  • Committer: Baptiste Lepilleur
  • Date: 2009-08-27 17:50:15 UTC
  • mfrom: (467.1.2 cpptl-integration)
  • Revision ID: blep@users.sourceforge.net-20090827175015-op04km4ev3b2x0f5
sync.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
}
82
82
 
83
83
 
84
 
#define CPPTL_CHECK_SORT_INT_VALUES( values )                              \
85
 
   {                                                                       \
86
 
      TestInt::serial = 0;                                                 \
87
 
      std::vector<TestInt> valuesOK;                                       \
88
 
      std::copy( values, values + sizeof(values)/sizeof(values[0]),        \
89
 
                 std::back_inserter( valuesOK ) );                         \
90
 
      std::vector<TestInt> valuesTest( valuesOK );                         \
91
 
      CppTL::smoothSort( &valuesTest[0], valuesTest.size() );              \
92
 
      std::stable_sort( valuesOK.begin(), valuesOK.end() );                \
93
 
      CPPUT_CHECK_SEQUENCE_EQUAL( CppTL::Enum::container(valuesOK),        \
94
 
                                  CppTL::Enum::container(valuesTest) );    \
95
 
   }
96
 
 
97
84
CPPUT_SUITE( "ShellSort" ) {
98
85
 
99
 
//
100
 
//
101
 
//CPPUT_TEST_FUNCTION_IN( testSmoothSort3, "ShellSort" )
102
 
//{
103
 
//   int a12[] = { 1,2 };
104
 
//   CPPTL_CHECK_SORT_INT_VALUES( a12 );
105
 
//   int a21[] = { 2,1 };
106
 
//   CPPTL_CHECK_SORT_INT_VALUES( a21 );
107
 
//   int a312[] = { 3,1,2 };
108
 
//   CPPTL_CHECK_SORT_INT_VALUES( a312 );
109
 
//}
110
 
 
111
86
 
112
87
CPPUT_TEST_FUNCTION( testShellSortRandom )
113
88
{
115
90
   {
116
91
      TestInt::serial = 0;
117
92
      int length = (rand() % 5000) + 1;
118
 
      std::vector<TestInt> data( length );
 
93
      std::deque<TestInt> data( length );
119
94
      for ( int index = 0; index < length; ++index )
120
95
      {
121
96
         data[index] = rand() % length;
122
97
      }
123
 
      std::vector<TestInt> actual( data );
 
98
      std::deque<TestInt> actual( data );
124
99
      CppTL::shellSort( actual.begin(), actual.end() );
125
 
      std::vector<TestInt> expected( data);
 
100
      std::deque<TestInt> expected( data);
126
101
      std::sort( expected.begin(), expected.end() );
127
102
      CPPUT_CHECK_SEQUENCE_EQUAL( CppTL::Enum::container(expected),
128
103
                                  CppTL::Enum::container(actual) );