Show
Ignore:
Timestamp:
11/13/09 16:11:31 (15 years ago)
Author:
mido
Message:

astyler run over all test sources
general_suite added
cleanup of \test directory finished

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/tests/epdf_harness.cpp

    r713 r722  
    2828        UI::get ( variance, set, "variance", UI::compulsory ); 
    2929 
    30         UI::get (support, set, "support", UI::optional ); 
    31         UI::get (nbins, set, "nbins", UI::optional ); 
    32         UI::get (nsamples, set, "nsamples", UI::optional ); 
    33         UI::get (R, set, "R", UI::optional ); 
    34  
    35         mrv = UI::build<RV> (set, "marginal_rv", UI::optional ); 
     30        UI::get ( support, set, "support", UI::optional ); 
     31        UI::get ( nbins, set, "nbins", UI::optional ); 
     32        UI::get ( nsamples, set, "nsamples", UI::optional ); 
     33        UI::get ( R, set, "R", UI::optional ); 
     34 
     35        mrv = UI::build<RV> ( set, "marginal_rv", UI::optional ); 
    3636 
    3737        UI::get ( tolerance, set, "tolerance", UI::optional ); 
     
    7474                mprod mEp ( aa ); 
    7575 
    76                 check_cond_mean(mEp); 
     76                check_cond_mean ( mEp ); 
    7777                if ( R.rows() > 0 ) { 
    78                         check_cond_covariance( mEp ); 
     78                        check_cond_covariance ( mEp ); 
    7979                } 
    8080 
    8181                // test of pdflog at zero 
    8282                vec zero ( 0 ); 
    83                 vec zeron=zeros ( hepdf->dimension() ); 
     83                vec zeron = zeros ( hepdf->dimension() ); 
    8484 
    8585                double lpz = hepdf->evallog ( zeron ); 
    86                 double lpzc=mEp.evallogcond ( zeron, zero ); 
     86                double lpzc = mEp.evallogcond ( zeron, zero ); 
    8787                CHECK_CLOSE_EX ( lpz, lpzc, tolerance ); 
    8888 
    89                 vec lpzv(1); 
    90                 lpzv(0) = lpz; 
     89                vec lpzv ( 1 ); 
     90                lpzv ( 0 ) = lpz; 
    9191 
    9292                mat zero1n ( hepdf->dimension(), 1 ); 
     
    9898                CHECK_CLOSE_EX ( lpzv, lpzv_act, tolerance ); 
    9999 
    100                 Array<vec> zeroa(3); 
    101                 lpzv = vec( zeroa.size() ); 
     100                Array<vec> zeroa ( 3 ); 
     101                lpzv = vec ( zeroa.size() ); 
    102102                for ( int i = 0; i < zeroa.size(); ++i ) { 
    103                         zeroa(i) = zeron; 
    104                         lpzv(i) = lpz; 
     103                        zeroa ( i ) = zeron; 
     104                        lpzv ( i ) = lpz; 
    105105                } 
    106106 
     
    115115 
    116116        int tc = 0; 
    117         Array<vec> actual(CurrentContext::max_trial_count); 
     117        Array<vec> actual ( CurrentContext::max_trial_count ); 
    118118        do { 
    119119                vec emu = num_mean2 ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); 
    120                 actual( tc ) = emu; 
    121                 ++tc; 
    122         } while ( ( tc < CurrentContext::max_trial_count ) && 
    123                   !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) ); 
    124         if ( ( tc == CurrentContext::max_trial_count ) && 
    125              ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
    126                 UnitTest::MemoryOutStream stream; 
    127                 stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 
    128  
    129                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
    130  
    131                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    132        } 
     120                actual ( tc ) = emu; 
     121                ++tc; 
     122        } while ( ( tc < CurrentContext::max_trial_count ) && 
     123                  !UnitTest::AreClose ( mean, actual ( tc - 1 ), tolerance ) ); 
     124        if ( ( tc == CurrentContext::max_trial_count ) && 
     125                ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
     126                UnitTest::MemoryOutStream stream; 
     127                stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 
     128 
     129                UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 
     130 
     131                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     132        } 
    133133} 
    134134 
     
    138138 
    139139        int tc = 0; 
    140         Array<double> actual(CurrentContext::max_trial_count); 
     140        Array<double> actual ( CurrentContext::max_trial_count ); 
    141141        do { 
    142142                double nc = normcoef ( hepdf.get(), xb, yb, nbins ( 0 ), nbins ( 1 ) ); 
    143                 actual( tc ) = nc; 
    144                 ++tc; 
    145         } while ( ( tc < CurrentContext::max_trial_count ) && 
    146                   !UnitTest::AreClose ( 1.0, actual( tc - 1 ), tolerance ) ); 
    147         if ( ( tc == CurrentContext::max_trial_count ) && 
    148              ( !UnitTest::AreClose ( 1.0, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
    149                 UnitTest::MemoryOutStream stream; 
    150                 stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 
    151  
    152                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
    153  
    154                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    155        } 
     143                actual ( tc ) = nc; 
     144                ++tc; 
     145        } while ( ( tc < CurrentContext::max_trial_count ) && 
     146                  !UnitTest::AreClose ( 1.0, actual ( tc - 1 ), tolerance ) ); 
     147        if ( ( tc == CurrentContext::max_trial_count ) && 
     148                ( !UnitTest::AreClose ( 1.0, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
     149                UnitTest::MemoryOutStream stream; 
     150                stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 
     151 
     152                UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 
     153 
     154                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     155        } 
    156156} 
    157157 
     
    160160 
    161161        int tc = 0; 
    162         Array<vec> actual(CurrentContext::max_trial_count); 
     162        Array<vec> actual ( CurrentContext::max_trial_count ); 
    163163        do { 
    164164                mat smp = hepdf->sample_mat ( nsamples ); 
    165165                vec emu = smp * ones ( nsamples ) / nsamples; 
    166                 actual( tc ) = emu; 
    167                 ++tc; 
    168         } while ( ( tc < CurrentContext::max_trial_count ) && 
    169                   !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); 
    170         if ( ( tc == CurrentContext::max_trial_count ) && 
    171              ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 
    172                 UnitTest::MemoryOutStream stream; 
    173                 stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; 
    174  
    175                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
    176  
    177                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    178        } 
     166                actual ( tc ) = emu; 
     167                ++tc; 
     168        } while ( ( tc < CurrentContext::max_trial_count ) && 
     169                  !UnitTest::AreClose ( mean, actual ( tc - 1 ), delta ) ); 
     170        if ( ( tc == CurrentContext::max_trial_count ) && 
     171                ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 
     172                UnitTest::MemoryOutStream stream; 
     173                stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << delta << " but was " << actual; 
     174 
     175                UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 
     176 
     177                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     178        } 
    179179} 
    180180 
    181181void epdf_harness::check_covariance() { 
    182182        int tc = 0; 
    183         Array<mat> actual(CurrentContext::max_trial_count); 
     183        Array<mat> actual ( CurrentContext::max_trial_count ); 
    184184        do { 
    185185                mat smp = hepdf->sample_mat ( nsamples ); 
    186186                vec emu = smp * ones ( nsamples ) / nsamples; 
    187187                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
    188                 actual( tc ) = er; 
    189                 ++tc; 
    190         } while ( ( tc < CurrentContext::max_trial_count ) && 
    191                   !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); 
    192          
    193         if ( ( tc == CurrentContext::max_trial_count ) && 
    194              ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
    195                 UnitTest::MemoryOutStream stream; 
    196                 stream << CurrentContext::format_context(__LINE__) << "expected " << R << " +/- " << tolerance << " but was " << actual; 
    197  
    198                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
    199  
    200                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    201        } 
    202 } 
    203  
    204 void epdf_harness::check_cond_mean( mprod &mep ) { 
     188                actual ( tc ) = er; 
     189                ++tc; 
     190        } while ( ( tc < CurrentContext::max_trial_count ) && 
     191                  !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 
     192 
     193        if ( ( tc == CurrentContext::max_trial_count ) && 
     194                ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
     195                UnitTest::MemoryOutStream stream; 
     196                stream << CurrentContext::format_context ( __LINE__ ) << "expected " << R << " +/- " << tolerance << " but was " << actual; 
     197 
     198                UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 
     199 
     200                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     201        } 
     202} 
     203 
     204void epdf_harness::check_cond_mean ( mprod &mep ) { 
    205205        vec delta = make_close_tolerance ( variance, nsamples ); 
    206206 
    207207        int tc = 0; 
    208         Array<vec> actual(CurrentContext::max_trial_count); 
     208        Array<vec> actual ( CurrentContext::max_trial_count ); 
    209209        do { 
    210210                mat smp = mep.samplecond_mat ( vec ( 0 ), nsamples ); 
    211211                vec emu = sum ( smp, 2 ) / nsamples; 
    212                 actual( tc ) = emu; 
    213                 ++tc; 
    214         } while ( ( tc < CurrentContext::max_trial_count ) && 
    215                   !UnitTest::AreClose ( mean, actual( tc - 1 ), delta ) ); 
    216         if ( ( tc == CurrentContext::max_trial_count ) && 
    217              ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 
    218                 UnitTest::MemoryOutStream stream; 
    219                 stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << delta << " but was " << actual; 
    220  
    221                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
    222  
    223                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    224        } 
    225 } 
    226  
    227 void epdf_harness::check_cond_covariance( mprod &mep ) { 
    228         int tc = 0; 
    229         Array<mat> actual(CurrentContext::max_trial_count); 
     212                actual ( tc ) = emu; 
     213                ++tc; 
     214        } while ( ( tc < CurrentContext::max_trial_count ) && 
     215                  !UnitTest::AreClose ( mean, actual ( tc - 1 ), delta ) ); 
     216        if ( ( tc == CurrentContext::max_trial_count ) && 
     217                ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), delta ) ) ) { 
     218                UnitTest::MemoryOutStream stream; 
     219                stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << delta << " but was " << actual; 
     220 
     221                UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 
     222 
     223                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     224        } 
     225} 
     226 
     227void epdf_harness::check_cond_covariance ( mprod &mep ) { 
     228        int tc = 0; 
     229        Array<mat> actual ( CurrentContext::max_trial_count ); 
    230230        do { 
    231231                mat smp = mep.samplecond_mat ( vec ( 0 ), nsamples ); 
    232232                vec emu = sum ( smp, 2 ) / nsamples; 
    233233                mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 
    234                 actual( tc ) = er; 
    235                 ++tc; 
    236         } while ( ( tc < CurrentContext::max_trial_count ) && 
    237                   !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); 
    238         if ( ( tc == CurrentContext::max_trial_count ) && 
    239              ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
    240                 UnitTest::MemoryOutStream stream; 
    241                 stream << CurrentContext::format_context(__LINE__) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 
    242  
    243                 UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), 0, false); 
    244  
    245                 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
    246        } 
    247 } 
    248  
    249 } 
     234                actual ( tc ) = er; 
     235                ++tc; 
     236        } while ( ( tc < CurrentContext::max_trial_count ) && 
     237                  !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 
     238        if ( ( tc == CurrentContext::max_trial_count ) && 
     239                ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 
     240                UnitTest::MemoryOutStream stream; 
     241                stream << CurrentContext::format_context ( __LINE__ ) << "expected " << mean << " +/- " << tolerance << " but was " << actual; 
     242 
     243                UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), 0, false ); 
     244 
     245                UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 
     246        } 
     247} 
     248 
     249}