Show
Ignore:
Timestamp:
08/07/09 09:57:52 (15 years ago)
Author:
vbarta
Message:

repeating failing mpdf tests; mpdf_harness configs now have optional cond (0 by default) and mandatory variance

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/mpdf_harness.cpp

    r480 r484  
    2828void mpdf_harness::from_setting ( const Setting &set ) { 
    2929        hmpdf = UI::build<mpdf> ( set, "mpdf", UI::compulsory ); 
    30         UI::get ( cond, set, "cond", UI::compulsory ); 
    3130        UI::get ( mean, set, "mean", UI::compulsory ); 
     31        UI::get ( variance, set, "variance", UI::compulsory ); 
     32 
     33        if ( !UI::get ( cond, set, "cond", UI::optional ) ) { 
     34                cond = zeros ( hmpdf->dimensionc() ); 
     35        } 
    3236 
    3337        UI::get ( nsamples, set, "nsamples", UI::optional ); 
     
    3842void mpdf_harness::test ( const char *config_name, int idx ) { 
    3943        CurrentContext cc ( config_name, idx ); 
    40  
    41         mat smp = hmpdf->samplecond_m ( cond, nsamples ); 
    42         int n = smp.cols(); 
    43         vec emu = smp * ones ( n ) / n; 
    44         mat er = ( smp * smp.T() ) / n - outer_product ( emu, emu ); 
    45         CHECK_CLOSE_EX ( mean, emu, tolerance ); 
    46  
     44        check_mean(); 
    4745        if ( R.rows() > 0 ) { 
    48                 CHECK_CLOSE_EX ( R, er, tolerance ); 
     46                check_covariance(); 
    4947        } 
    5048} 
    5149 
     50void mpdf_harness::check_mean() { 
     51        vec delta = make_close_tolerance ( variance, nsamples ); 
     52 
     53        int tc = 0; 
     54        Array<vec> actual(CurrentContext::max_trial_count); 
     55        do { 
     56                mat smp = hmpdf->samplecond_m ( cond, nsamples ); 
     57                vec emu = smp * ones ( nsamples ) / nsamples; 
     58                actual( tc ) = emu; 
     59                ++tc; 
     60        } while ( ( tc < CurrentContext::max_trial_count ) && 
     61                  !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); 
     62        if ( ( tc == CurrentContext::max_trial_count ) && 
     63             ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 
     64                UnitTest::MemoryOutStream stream; 
     65                stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; 
     66 
     67                UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
     68 
     69                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     70       } 
    5271} 
     72 
     73void mpdf_harness::check_covariance() { 
     74        int tc = 0; 
     75        Array<mat> actual(CurrentContext::max_trial_count); 
     76        do { 
     77                mat smp = hmpdf->samplecond_m ( cond, nsamples ); 
     78                vec emu = smp * ones ( nsamples ) / nsamples; 
     79                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
     80                actual( tc ) = er; 
     81                ++tc; 
     82        } while ( ( tc < CurrentContext::max_trial_count ) && 
     83                  !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); 
     84        if ( ( tc == CurrentContext::max_trial_count ) && 
     85             ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
     86                UnitTest::MemoryOutStream stream; 
     87                stream << CurrentContext::format_context(__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual; 
     88 
     89                UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
     90 
     91                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     92       } 
     93} 
     94 
     95}