root/library/tests/mpdf_harness.cpp @ 482

Revision 480, 1.4 kB (checked in by vbarta, 15 years ago)

fixed tests for new UI::get & UI::build

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", UI::compulsory );
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", UI::compulsory );
30        UI::get ( cond, set, "cond", UI::compulsory );
31        UI::get ( mean, set, "mean", UI::compulsory );
32
33        UI::get ( nsamples, set, "nsamples", UI::optional );
34        UI::get ( R, set, "R", UI::optional );
35        UI::get ( tolerance, set, "tolerance", UI::optional );
36}
37
38void mpdf_harness::test ( const char *config_name, int idx ) {
39        CurrentContext cc ( config_name, idx );
40
41        mat smp = hmpdf->samplecond_m ( cond, nsamples );
42        int n = smp.cols();
43        vec emu = smp * ones ( n ) / n;
44        mat er = ( smp * smp.T() ) / n - outer_product ( emu, emu );
45        CHECK_CLOSE_EX ( mean, emu, tolerance );
46
47        if ( R.rows() > 0 ) {
48                CHECK_CLOSE_EX ( R, er, tolerance );
49        }
50}
51
52}
Note: See TracBrowser for help on using the browser.