Changeset 1704 for trunk


Ignore:
Timestamp:
Jan 8, 2009, 6:17:44 PM (12 years ago)
Author:
Peter
Message:

avoid using abs in tests and use test::Suite instead

Location:
trunk/test
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/averager_test.cc

    r1664 r1704  
    55  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    66  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2009 Peter Johansson
    78
    89  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    99100
    100101  a.add(3,5);
    101   if (std::abs(a.standard_error()-sqrt(a.variance()/a.n()))>
    102       std::numeric_limits<double>().round_error() ){
     102  if (!suite.equal_sqrt(a.standard_error(), sqrt(a.variance()/a.n()),1)) {
    103103    suite.add(false);
    104104    suite.err() << "error: standard_error\n";
     
    185185  for (int i=0; i<10; i++)
    186186    ap.add(static_cast<double>(i),i);
    187   if (std::abs(ap.correlation()-1)>tol){
     187  if (!suite.equal(ap.correlation(),1,tol)){
    188188    suite.add(false);
    189189    suite.err() << "correlation: " << ap.correlation() << std::endl;
     
    191191           << std::endl;
    192192  }
    193   if (ap.x_averager().variance()!=ap.covariance()){
     193  if (!suite.equal(ap.x_averager().variance(),ap.covariance())) {
    194194    suite.add(false);
    195195    suite.err() << "error: covariance of identical vectors should equal to variance"
     
    201201  for (int i=0; i<8; i++)
    202202    ap.add(static_cast<double>(i),i,-1);
    203   if (std::abs(ap.correlation()-1)>tol) {
     203  if (!suite.equal(ap.correlation(),1, tol)) {
    204204    suite.add(false);
    205205    suite.err() << "correlation after removal of data: " << ap.correlation()
     
    253253           Suite& suite)
    254254{
    255 //  std::cout << (a.n()==b.n()) << std::endl;
    256 //  std::cout << (a.mean()==b.mean()) << std::endl;
    257 //  std::cout << (std::abs(a.variance()-b.variance()<1e-15)) << std::endl;
    258255  return (a.n()==b.n() && suite.equal(a.mean(),b.mean(),tol) &&
    259256          suite.equal(a.variance(),b.variance(),tol));
     
    305302{
    306303  bool ok = true;
    307   if  ( std::abs(a.covariance()-b.covariance())>tol){
     304  if (!suite.equal(a.covariance(), b.covariance(), tol)) {
    308305    suite.add(false);
    309306    suite.err() << "error covariance: " << a.covariance() << "\t"
    310307           << b.covariance() << std::endl;
    311308  }
    312   if ( std::abs(a.correlation()-b.correlation())>tol ) {
     309  if ( !suite.equal(a.correlation(),b.correlation(), tol)) {
    313310    suite.add(false);
    314311    suite.err() << "error correlation" << std::endl;
     
    321318{
    322319  bool ok = true;
    323   if  ( std::abs(a.covariance()-b.covariance())>tol){
     320  if (!suite.equal(a.covariance(), b.covariance(), tol) ) {
    324321    suite.add(false);
    325322    suite.err() << "error covariance: " << a.covariance() << "\t"
    326323           << b.covariance() << std::endl;
    327324  }
    328   if ( std::abs(a.correlation()-b.correlation())>tol ) {
     325  if ( !suite.equal(a.correlation(),b.correlation(), tol) ) {
    329326    suite.add(false);
    330327    suite.err() << "error correlation" << std::endl;
  • trunk/test/distance_test.cc

    r1665 r1704  
    33/*
    44  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
     5  Copyright (C) 2009 Peter Johansson
    56
    67  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    8384  b(2) = 1;
    8485 
    85   double tolerance=1e-4;
    8686  statistics::EuclideanDistance eucl_dist;
    8787  suite.err() << "testing EuclideanDistance" << std::endl;
     
    135135  sb[2] = 1;
    136136 
     137  double tolerance=1e-4;
    137138  dist=eucl_dist(sa.begin(),sa.end(),sb.begin());
    138   if(std::abs(dist-2.23607)>tolerance) {
     139  if(!suite.equal_fix(dist, 2.23607,tolerance)) {
    139140    suite.err() << "Error in distance for std::vector " << std::endl;
    140141    suite.add(false);
     
    145146  std::copy(sa.begin(),sa.end(),std::back_inserter<std::list<double> >(la));
    146147  dist=eucl_dist(la.begin(),la.end(),sb.begin());
    147   if(std::abs(dist-2.23607)>tolerance) {
     148  if(!suite.equal_fix(dist, 2.23607, tolerance) ) {
    148149    suite.err() << "Error in distance for std::list " << std::endl;
    149150    suite.add(false);
     
    245246  utility::Matrix x = data();
    246247  double self = dist(x.begin(), x.end(), x.begin());
    247   if (!(std::abs(self) <= N*std::numeric_limits<double>().epsilon()) ){
     248  if (!suite.equal_fix(self,0, N*std::numeric_limits<double>().epsilon()) ) {
    248249    suite.err() << "error: self distance is " << self << "\n"
    249250                << "supposed to be zero.\n";
  • trunk/test/feature_selection_test.cc

    r1584 r1704  
    44  Copyright (C) 2006 Jari Häkkinen, Peter Johansson
    55  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
    6   Copyright (C) 2008 Peter Johansson
     6  Copyright (C) 2008, 2009 Peter Johansson
    77
    88  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    8888
    8989  classifier::DataLookupWeighted1D row(dataviewweighted,best_feature,true);
    90   double score_diff=std::abs(snr.score(targets,row)-1.47804);
    91   if(score_diff>0.00001) {
     90  if(!suite.equal_fix(snr.score(targets, row), 1.47804, 0.00001) ) {
    9291    suite.err() << "\nERROR: Best score not what expected!\n" << std::endl;
    9392    suite.add(false);
  • trunk/test/kernel_test.cc

    r1487 r1704  
    55  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    66  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
     7  Copyright (C) 2009 Peter Johansson
    78
    89  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    140141  for(size_t i=0;i<control.rows();i++)
    141142    for(size_t j=0;j<control.columns();j++)
    142       if (std::abs(kernel(i,j)-control(i,j))>error_bound){
     143      if (!suite.equal_fix(kernel(i,j),control(i,j), error_bound) ){
    143144        suite.err() << "ERROR: comparing kernel(" << i << "," << j << "): "
    144145                    << kernel(i,j)
     
    184185  for(size_t i=0;i<control.rows();i++)
    185186    for(size_t j=0;j<control.columns();j++)
    186       if (std::abs(kernel(i,j)-control(i,j))>error_bound){
     187      if (!suite.equal_fix(kernel(i,j), control(i,j), error_bound) ){
    187188        suite.err() << "ERROR: comparing kernel(" << i << "," << j << "): "
    188189                    << kernel(i,j)
  • trunk/test/kolmogorov_smirnov_test.cc

    r1701 r1704  
    107107  double p_correct = 0.2;
    108108  double margin=10*std::sqrt(p_correct*(1-p_correct)/n);
    109   if (std::abs(p-p_correct)>margin) {
     109  if (!suite.equal_fix(p, p_correct, margin) ) {
    110110    suite.add(false);
    111111    suite.err() << "Error: p = " << p << "\n"
     
    132132  double margin = 5 * a.standard_error();
    133133  double p_approx = ks.p_value();
    134   if (std::abs(a.mean()-p_approx)>margin) {
     134  if (!suite.equal_fix(a.mean(), p_approx, margin) ) {
    135135    suite.add(false);
    136136    suite.err() << "Error: unexpected large deviation between p_values\n"
Note: See TracChangeset for help on using the changeset viewer.