Ignore:
Timestamp:
Apr 11, 2010, 1:05:12 AM (12 years ago)
Author:
Peter
Message:

closes #612

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility_test.cc

    r2209 r2239  
    6060void test_sort_index(test::Suite& suite);
    6161void test_less_nan(test::Suite& suite);
     62void test_ptr_compare(test::Suite& suite);
    6263
    6364int main(int argc, char* argv[])
     
    168169  test_less_nan(suite);
    169170  test_errno_error(suite);
     171  test_ptr_compare(suite);
    170172
    171173  return suite.return_value();
     
    370372  }
    371373}
     374
     375void test_ptr_compare(test::Suite& suite)
     376{
     377  double* a = new double(0);
     378  double* b = new double(1);
     379
     380  utility::PtrCompare<double> ptr_less;
     381  if (!ptr_less(a, b)) {
     382    suite.out() << "ptr_less(a, b) returned false\n";
     383    suite.add(false);
     384  }
     385  if (ptr_less(b, a)) {
     386    suite.out() << "ptr_less(b, a) returned true\n";
     387    suite.add(false);
     388  }
     389
     390  utility::PtrCompare<double, std::greater<double> > ptr_greater;
     391  if (ptr_greater(a, b)) {
     392    suite.out() << "ptr_greater(a, b) returned true\n";
     393    suite.add(false);
     394  }
     395  if (!ptr_greater(b, a)) {
     396    suite.out() << "ptr_greater(b, a) returned false\n";
     397    suite.add(false);
     398  }
     399  delete a;
     400  delete b;
     401
     402  std::vector<double*> vec(10);
     403  std::greater<double> d_greater;
     404  utility::PtrCompare<double, std::greater<double> > ptr_greater2(d_greater);
     405  for (size_t i=0; i<vec.size(); ++i)
     406    vec[i] = new double(i);
     407  std::sort(vec.begin(), vec.end(), ptr_greater2);
     408  for (size_t i=1; i<vec.size(); ++i) {
     409    suite.add( *vec[i-1] > *vec[i]);
     410  }
     411  for (size_t i=0; i<vec.size(); ++i)
     412    delete vec[i];
     413
     414}
Note: See TracChangeset for help on using the changeset viewer.