| | 90 | |
| | 91 | static void check_mean ( emix &distrib_obj, int nsamples, const vec &mean, double tolerance ) { |
| | 92 | int tc = 0; |
| | 93 | Array<vec> actual(CurrentContext::max_trial_count); |
| | 94 | do { |
| | 95 | mat smp = distrib_obj.sample_m ( nsamples ); |
| | 96 | vec emu = sum ( smp, 2 ) / nsamples; |
| | 97 | actual( tc ) = emu; |
| | 98 | ++tc; |
| | 99 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 100 | !UnitTest::AreClose ( mean, actual( tc - 1 ), tolerance ) ); |
| | 101 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 102 | ( !UnitTest::AreClose ( mean, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 103 | UnitTest::MemoryOutStream stream; |
| | 104 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), __LINE__); |
| | 105 | stream << "Expected " << mean << " +/- " << tolerance << " but was " << actual; |
| | 106 | |
| | 107 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 108 | } |
| | 109 | } |
| | 110 | |
| | 111 | static void check_covariance ( emix &distrib_obj, int nsamples, const mat &R, double tolerance) { |
| | 112 | int tc = 0; |
| | 113 | Array<mat> actual(CurrentContext::max_trial_count); |
| | 114 | do { |
| | 115 | mat smp = distrib_obj.sample_m ( nsamples ); |
| | 116 | vec emu = sum ( smp, 2 ) / nsamples; |
| | 117 | mat er = ( smp * smp.T() ) / nsamples - outer_product ( emu, emu ); |
| | 118 | actual( tc ) = er; |
| | 119 | ++tc; |
| | 120 | } while ( ( tc < CurrentContext::max_trial_count ) && |
| | 121 | !UnitTest::AreClose ( R, actual( tc - 1 ), tolerance ) ); |
| | 122 | if ( ( tc == CurrentContext::max_trial_count ) && |
| | 123 | ( !UnitTest::AreClose ( R, actual( CurrentContext::max_trial_count - 1 ), tolerance ) ) ) { |
| | 124 | UnitTest::MemoryOutStream stream; |
| | 125 | UnitTest::TestDetails details(*UnitTest::CurrentTest::Details(), __LINE__); |
| | 126 | stream << "Expected " << R << " +/- " << tolerance << " but was " << actual; |
| | 127 | |
| | 128 | UnitTest::CurrentTest::Results()->OnTestFailure ( details, stream.GetText() ); |
| | 129 | } |
| | 130 | } |