Changeset 722 for library/tests/testsuite/emix_test.cpp
- Timestamp:
- 11/13/09 16:11:31 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/testsuite/emix_test.cpp
r721 r722 13 13 static void check_mean ( emix &distrib_obj, int nsamples, const vec &mean, double tolerance ); 14 14 15 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance );15 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance ); 16 16 17 17 TEST ( emix_test ) { … … 46 46 pdf_ptr Ac = E1->condition ( y ); 47 47 48 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *> ( Ac.get() );49 CHECK (wacnd);48 mlnorm<ldmat> *wacnd = dynamic_cast<mlnorm<ldmat> *> ( Ac.get() ); 49 CHECK ( wacnd ); 50 50 if ( wacnd ) { 51 51 CHECK_CLOSE ( mat ( "-0.349953" ), wacnd->_A(), epsilon ); … … 83 83 84 84 mat observedR ( "0.740142 -0.259015; -0.259015 1.0302" ); 85 check_covariance ( M2, N, observedR, 2.0 );85 check_covariance ( M2, N, observedR, 2.0 ); 86 86 87 87 epdf_ptr Mg = M2.marginal ( y ); … … 97 97 static void check_mean ( emix &distrib_obj, int nsamples, const vec &mean, double tolerance ) { 98 98 int tc = 0; 99 Array<vec> actual (CurrentContext::max_trial_count);99 Array<vec> actual ( CurrentContext::max_trial_count ); 100 100 do { 101 101 mat smp = distrib_obj.sample_mat ( nsamples ); 102 102 vec emu = sum ( smp, 2 ) / nsamples; 103 actual ( tc ) = emu;103 actual ( tc ) = emu; 104 104 ++tc; 105 105 } while ( ( tc < CurrentContext::max_trial_count ) && 106 !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) );106 !UnitTest::AreClose ( mean, actual ( tc - 1 ), tolerance ) ); 107 107 if ( ( tc == CurrentContext::max_trial_count ) && 108 ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {108 ( !UnitTest::AreClose ( mean, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 109 109 UnitTest::MemoryOutStream stream; 110 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), __LINE__);110 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), __LINE__ ); 111 111 stream << "Expected " << mean << " +/- " << tolerance << " but was " << actual; 112 112 … … 115 115 } 116 116 117 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance ) {117 static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance ) { 118 118 int tc = 0; 119 Array<mat> actual (CurrentContext::max_trial_count);119 Array<mat> actual ( CurrentContext::max_trial_count ); 120 120 do { 121 121 mat smp = distrib_obj.sample_mat ( nsamples ); 122 122 vec emu = sum ( smp, 2 ) / nsamples; 123 123 mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); 124 actual ( tc ) = er;124 actual ( tc ) = er; 125 125 ++tc; 126 126 } while ( ( tc < CurrentContext::max_trial_count ) && 127 !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) );127 !UnitTest::AreClose ( R, actual ( tc - 1 ), tolerance ) ); 128 128 if ( ( tc == CurrentContext::max_trial_count ) && 129 ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) {129 ( !UnitTest::AreClose ( R, actual ( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { 130 130 UnitTest::MemoryOutStream stream; 131 UnitTest::TestDetails details (*UnitTest::CurrentTest::Details(), __LINE__);131 UnitTest::TestDetails details ( *UnitTest::CurrentTest::Details(), __LINE__ ); 132 132 stream << "Expected " << R << " +/- " << tolerance << " but was " << actual; 133 133 134 134 UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); 135 135 } 136 136 }