root/library/tests/mpdf_harness.cpp @ 456

Revision 456, 1.3 kB (checked in by vbarta, 15 years ago)

custom test location for harness tests (extended UnitTest?++), configurable tolerance - all tests pass (most of the time)

Line 
1#include "mpdf_harness.h"
2#include "base/bdmbase.h"
3#include "base/user_info.h"
4#include "stat/exp_family.h"
5#include "mat_checks.h"
6#include "test_util.h"
7#include "UnitTest++.h"
8
9namespace bdm {
10
11template<>
12const ParticularUI<mpdf_harness> &ParticularUI<mpdf_harness>::factory(
13    ParticularUI<mpdf_harness>("mpdf_harness"));
14
15void mpdf_harness::test_config(const char *config_file_name) {
16    RV::clear_all();
17
18    UIFile in(config_file_name);
19    Array<mpdf_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}
27
28void mpdf_harness::from_setting(const Setting &set) {
29    hmpdf = UI::build<mpdf>(set, "mpdf");
30    UI::get(cond, set, "cond");
31    UI::get(mean, set, "mean");
32
33    if (set.exists("nsamples")) {
34        UI::get(nsamples, set, "nsamples");
35    }
36
37    UI::get(R, set, "R");
38
39    if (set.exists("tolerance")) {
40        UI::get(tolerance, set, "tolerance");
41    }
42}
43
44void mpdf_harness::test(const char *config_name, int idx)
45{
46    CurrentContext cc(config_name, idx);
47
48    mat smp = hmpdf->samplecond_m(cond, nsamples);
49    int n = smp.cols();
50    vec emu = smp * ones(n) / n;
51    mat er = (smp * smp.T()) / n - outer_product(emu, emu);
52    CHECK_CLOSE_EX(mean, emu, tolerance);
53    CHECK_CLOSE_EX(R, er, tolerance);
54}
55
56}
Note: See TracBrowser for help on using the browser.