Changeset 484 for library/tests
- Timestamp:
- 08/07/09 09:57:52 (15 years ago)
- Location:
- library/tests
- Files:
-
- 8 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/epdf_harness.cpp
r482 r484 142 142 143 143 void epdf_harness::check_sample_mean() { 144 // simplify overloading for Visual Studio 145 vec delta = 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 144 vec delta = make_close_tolerance ( variance, nsamples ); 146 145 147 146 int tc = 0; … … 164 163 } 165 164 } 166 167 165 168 166 void epdf_harness::check_covariance() { … … 189 187 190 188 void epdf_harness::check_cond_mean( mprod &mep ) { 191 // simplify overloading for Visual Studio 192 vec delta = 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 189 vec delta = make_close_tolerance ( variance, nsamples ); 193 190 194 191 int tc = 0; -
library/tests/mat_checks.h
r481 r484 51 51 } 52 52 53 } 54 55 /*! Constructs the multiple of standard deviation used for sample 56 tests (currently 2). */ 57 inline itpp::vec make_close_tolerance ( const itpp::vec & variance, int nsamples ) { 58 // simplify overloading for Visual Studio 59 return 2 * ( sqrt ( variance ) / sqrt ( static_cast<double> ( nsamples ) ) ); 53 60 } 54 61 -
library/tests/mepdf.cfg
r456 r484 18 18 mean = [ 1.1, -1.0 ]; 19 19 R = ( "matrix", 2, 2, [ 1.0, -0.5, -0.5, 2.0 ] ); 20 tolerance = 0.3; 20 tolerance = 0.1; 21 variance = [ 0.3, 0.3 ]; 21 22 } ); 22 23 -
library/tests/mgamma.cfg
r456 r484 20 20 mean = [ 1.5, 1.7 ]; 21 21 R = ( "matrix", 2, 2, [ 2.25, 0.0, 0.0, 2.89 ] ); 22 tolerance = 0.5; 22 variance = [ 0.4, 0.4 ]; 23 tolerance = 0.4; 23 24 } ); 24 25 -
library/tests/mlnorm.cfg
r462 r484 12 12 R = ( "matrix", 2, 2, [ 1.26402, 0.378231, 0.378231, 5.15925 ] ); 13 13 tolerance = 0.6; 14 variance = [ 0.2, 0.2 ]; 14 15 } ); 15 16 -
library/tests/mpdf_harness.cpp
r480 r484 28 28 void mpdf_harness::from_setting ( const Setting &set ) { 29 29 hmpdf = UI::build<mpdf> ( set, "mpdf", UI::compulsory ); 30 UI::get ( cond, set, "cond", UI::compulsory );31 30 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 } 32 36 33 37 UI::get ( nsamples, set, "nsamples", UI::optional ); … … 38 42 void mpdf_harness::test ( const char *config_name, int idx ) { 39 43 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(); 47 45 if ( R.rows() > 0 ) { 48 CHECK_CLOSE_EX ( R, er, tolerance);46 check_covariance(); 49 47 } 50 48 } 51 49 50 void 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 } 52 71 } 72 73 void 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 } -
library/tests/mpdf_harness.h
r477 r484 29 29 vec cond; 30 30 vec mean; 31 vec variance; 31 32 int nsamples; 32 33 mat R; … … 46 47 return hmpdf.get(); 47 48 } 49 50 private: 51 void check_mean(); 52 53 // assumes R is valid 54 void check_covariance(); 48 55 }; 49 56 -
library/tests/testsuite.cpp
r477 r484 1 1 #include "UnitTest++.h" 2 2 #include "itpp_ext.h" 3 #include <iostream> 4 #include <iomanip> 3 5 4 6 int main ( int, char const *[] ) { 5 7 itpp::RNG_randomize(); 6 return UnitTest::RunAllTests(); 8 try { 9 return UnitTest::RunAllTests(); 10 } catch ( std::exception const& e ) { 11 std::cerr << e.what() << std::endl; 12 return -1; 13 } 7 14 }