Changeset 456 for library/tests/epdf_harness.cpp
- Timestamp:
- 07/31/09 08:38:18 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
library/tests/epdf_harness.cpp
r447 r456 1 1 #include "epdf_harness.h" 2 #include "base/bdmbase.h" 3 #include "base/user_info.h" 2 4 #include "stat/exp_family.h" 3 5 #include "mat_checks.h" 4 6 #include "test_util.h" 5 7 #include "UnitTest++.h" 6 7 const double epsilon = 0.00001;8 9 namespace UnitTest10 {11 12 inline void CheckClose(TestResults &results, const itpp::vec &expected,13 const itpp::vec &actual, double tolerance,14 TestDetails const &details) {15 if (!AreClose(expected, actual, tolerance)) {16 MemoryOutStream stream;17 stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;18 19 results.OnTestFailure(details, stream.GetText());20 }21 }22 23 inline void CheckClose(TestResults &results, const itpp::mat &expected,24 const itpp::mat &actual, double tolerance,25 TestDetails const &details) {26 if (!AreClose(expected, actual, tolerance)) {27 MemoryOutStream stream;28 stream << "Expected " << expected << " +/- " << tolerance << " but was " << actual;29 30 results.OnTestFailure(details, stream.GetText());31 }32 }33 34 }35 8 36 9 namespace bdm { … … 39 12 const ParticularUI<epdf_harness> &ParticularUI<epdf_harness>::factory( 40 13 ParticularUI<epdf_harness>("epdf_harness")); 14 15 void epdf_harness::test_config(const char *config_file_name) { 16 RV::clear_all(); 17 18 UIFile in(config_file_name); 19 Array<epdf_harness *> input; 20 UI::get(input, in, "data"); 21 int sz = input.size(); 22 CHECK(sz > 0); 23 for (int i = 0; i < sz; ++i) { 24 input(i)->test(config_file_name, i); 25 } 26 } 41 27 42 28 void epdf_harness::from_setting(const Setting &set) { … … 64 50 UI::get(R, set, "R"); 65 51 } 52 53 if (set.exists("tolerance")) { 54 UI::get(tolerance, set, "tolerance"); 55 } 66 56 } 67 57 68 void epdf_harness::test( )58 void epdf_harness::test(const char *config_name, int idx) 69 59 { 70 CHECK_CLOSE(mean, hepdf->mean(), epsilon); 71 CHECK_CLOSE(variance, hepdf->variance(), epsilon); 60 CurrentContext cc(config_name, idx); 61 62 CHECK_CLOSE_EX(mean, hepdf->mean(), tolerance); 63 CHECK_CLOSE_EX(variance, hepdf->variance(), tolerance); 72 64 73 65 if (support.rows() == 2) { … … 85 77 } 86 78 87 CHECK_CLOSE (mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1);88 CHECK_CLOSE (integral, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1);79 CHECK_CLOSE_EX(mean, num_mean2(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 80 CHECK_CLOSE_EX(integral, normcoef(hepdf.get(), xb, yb, nbins(0), nbins(1)), 0.1); 89 81 } 90 82 … … 94 86 vec Emu = smp * ones(n) / n; 95 87 mat Er = (smp*smp.transpose())/n - outer_product(Emu,Emu); 96 CHECK_CLOSE (mean, Emu, 0.1);97 CHECK_CLOSE (R, Er, 0.1);88 CHECK_CLOSE_EX(mean, Emu, tolerance); 89 CHECK_CLOSE_EX(R, Er, tolerance); 98 90 } 99 91 }