root/library/tests/epdf_harness.cpp @ 436

Revision 436, 2.0 kB (checked in by vbarta, 15 years ago)

moved egiw_test to testsuite (partially converted to a configurable test); added public method clearing RVs

Line 
1#include "epdf_harness.h"
2#include "stat/exp_family.h"
3#include "mat_checks.h"
4#include "test_util.h"
5#include "UnitTest++.h"
6
7const double epsilon = 0.00001;
8
9namespace UnitTest
10{
11
12inline 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
23inline 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
36namespace bdm {
37
38template<>
39const ParticularUI<epdf_harness> &ParticularUI<epdf_harness>::factory(
40    ParticularUI<epdf_harness>("epdf_harness"));
41
42void epdf_harness::from_setting(const Setting &set) {
43    hepdf = UI::build<epdf>(set, "epdf");
44    UI::get(mean, set, "mean");
45    UI::get(variance, set, "variance");
46    UI::get(lognc, set, "lognc");
47    UI::get(support, set, "support");
48
49    if (set.exists("nsamples")) {
50        UI::get(nsamples, set, "nsamples");
51    }
52
53    UI::get(integral, set, "integral");
54}
55
56void epdf_harness::test()
57{
58    CHECK_CLOSE(mean, hepdf->mean(), epsilon);
59    CHECK_CLOSE(variance, hepdf->variance(), epsilon);
60
61    vec xb = support.get_row(0);
62    vec yb = support.get_row(1);
63    CHECK_CLOSE(mean, num_mean2(hepdf.get(), xb, yb, nsamples, nsamples), 0.1);
64    CHECK_CLOSE(integral, normcoef(hepdf.get(), xb, yb, nsamples, nsamples), 0.1);
65
66    egiw *wide = dynamic_cast<egiw *>(hepdf.get());
67    CHECK(wide);
68
69    CHECK_CLOSE(lognc, wide->lognc(), epsilon);
70}
71
72}
Note: See TracBrowser for help on using the browser.