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

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

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.