Show
Ignore:
Timestamp:
07/31/09 08:38:18 (15 years ago)
Author:
vbarta
Message:

custom test location for harness tests (extended UnitTest?++), configurable tolerance - all tests pass (most of the time)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/epdf_harness.cpp

    r447 r456  
    11#include "epdf_harness.h" 
     2#include "base/bdmbase.h" 
     3#include "base/user_info.h" 
    24#include "stat/exp_family.h" 
    35#include "mat_checks.h" 
    46#include "test_util.h" 
    57#include "UnitTest++.h" 
    6  
    7 const double epsilon = 0.00001; 
    8  
    9 namespace UnitTest 
    10 { 
    11  
    12 inline void CheckClose(TestResults &results, const itpp::vec &expected, 
    13                        const itpp::vec &actual, double tolerance, 
    14                        TestDetails const &details) { 
    15     if (!AreClose(expected, actual, tolerance)) {  
    16         MemoryOutStream stream; 
    17         stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual; 
    18  
    19         results.OnTestFailure(details, stream.GetText()); 
    20     } 
    21 } 
    22  
    23 inline void CheckClose(TestResults &results, const itpp::mat &expected, 
    24                        const itpp::mat &actual, double tolerance, 
    25                        TestDetails const &details) { 
    26     if (!AreClose(expected, actual, tolerance)) {  
    27         MemoryOutStream stream; 
    28         stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual; 
    29  
    30         results.OnTestFailure(details, stream.GetText()); 
    31     } 
    32 } 
    33  
    34 } 
    358 
    369namespace bdm { 
     
    3912const ParticularUI<epdf_harness> &ParticularUI<epdf_harness>::factory( 
    4013    ParticularUI<epdf_harness>("epdf_harness")); 
     14 
     15void epdf_harness::test_config(const char *config_file_name) { 
     16    RV::clear_all(); 
     17 
     18    UIFile in(config_file_name); 
     19    Array<epdf_harness *> input; 
     20    UI::get(input, in, "data"); 
     21    int sz = input.size(); 
     22    CHECK(sz > 0); 
     23    for (int i = 0; i < sz; ++i) { 
     24        input(i)->test(config_file_name, i); 
     25    } 
     26} 
    4127 
    4228void epdf_harness::from_setting(const Setting &set) { 
     
    6450        UI::get(R, set, "R"); 
    6551    } 
     52 
     53    if (set.exists("tolerance")) { 
     54        UI::get(tolerance, set, "tolerance"); 
     55    } 
    6656} 
    6757 
    68 void epdf_harness::test() 
     58void epdf_harness::test(const char *config_name, int idx) 
    6959{ 
    70     CHECK_CLOSE(mean, hepdf->mean(), epsilon); 
    71     CHECK_CLOSE(variance, hepdf->variance(), epsilon); 
     60    CurrentContext cc(config_name, idx); 
     61 
     62    CHECK_CLOSE_EX(mean, hepdf->mean(), tolerance); 
     63    CHECK_CLOSE_EX(variance, hepdf->variance(), tolerance); 
    7264 
    7365    if (support.rows() == 2) { 
     
    8577        } 
    8678 
    87         CHECK_CLOSE(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 
    88         CHECK_CLOSE(integral, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 
     79        CHECK_CLOSE_EX(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 
     80        CHECK_CLOSE_EX(integral, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 
    8981    } 
    9082 
     
    9486        vec Emu = smp * ones(n) / n; 
    9587        mat Er = (smp*smp.transpose())/n - outer_product(Emu,Emu); 
    96         CHECK_CLOSE(mean, Emu, 0.1); 
    97         CHECK_CLOSE(R, Er, 0.1); 
     88        CHECK_CLOSE_EX(mean, Emu, tolerance); 
     89        CHECK_CLOSE_EX(R, Er, tolerance); 
    9890    } 
    9991}