1 | #include "../bdm/base/datasources.h" |
---|
2 | #include "../bdm/base/loggers.h" |
---|
3 | #include "../mat_checks.h" |
---|
4 | #include "UnitTest++.h" |
---|
5 | |
---|
6 | using namespace bdm; |
---|
7 | |
---|
8 | TEST ( EpdfDS_test ) { |
---|
9 | UIFile uif ( "epdfds.cfg" ); |
---|
10 | shared_ptr<EpdfDS> ds = UI::build<EpdfDS> ( uif, "ds" ); |
---|
11 | |
---|
12 | vec mean = zeros ( 2 ); |
---|
13 | vec dt = zeros ( 2 ); |
---|
14 | for ( int i = 0; i < 100; i++ ) { |
---|
15 | ds->step(); |
---|
16 | ds->getdata ( dt ); |
---|
17 | mean += dt; |
---|
18 | } |
---|
19 | CHECK_CLOSE_EX ( vec_2 ( 1.0, 2.0 ) , mean / 100, 1e-2 ); |
---|
20 | } |
---|
21 | |
---|
22 | TEST ( PdfDS_test ) { |
---|
23 | UIFile uif ( "pdfds.cfg" ); |
---|
24 | |
---|
25 | shared_ptr<PdfDS> ds = UI::build<PdfDS> ( uif, "ds", UI::compulsory ); |
---|
26 | |
---|
27 | vec dt = zeros ( 2 ); |
---|
28 | vec ut = "1.0"; |
---|
29 | ds->write ( ut ); |
---|
30 | for ( int i = 0; i < 100; i++ ) { |
---|
31 | ds->step(); |
---|
32 | } |
---|
33 | ds->getdata ( dt ); |
---|
34 | CHECK_CLOSE ( -0.2 , dt ( 0 ), 1e-4 ); |
---|
35 | |
---|
36 | ut = "2.0"; |
---|
37 | ds->write ( ut ); |
---|
38 | for ( int i = 0; i < 100; i++ ) { |
---|
39 | ds->step(); |
---|
40 | } |
---|
41 | ds->getdata ( dt ); |
---|
42 | CHECK_CLOSE ( -0.4 , dt ( 0 ), 1e-4 ); |
---|
43 | } |
---|
44 | |
---|
45 | TEST ( StateDS_test ) { |
---|
46 | RV y ( "y", 1 ); |
---|
47 | RV u ( "u", 1 ); |
---|
48 | RV x ( "x", 2 ); |
---|
49 | |
---|
50 | shared_ptr<mlnorm<fsqmat> > IM = new mlnorm<fsqmat>; |
---|
51 | IM->set_parameters ( mat ( "1 2 0.5; 0 1 0.3" ), zeros ( 2 ), fsqmat ( 1e-10*eye ( 2 ) ) ); |
---|
52 | IM->set_rv ( x ); |
---|
53 | IM->set_rvc ( concat ( x.copy_t ( -1 ), u ) ); |
---|
54 | IM->validate(); |
---|
55 | |
---|
56 | shared_ptr<mlnorm<fsqmat> > OM = new mlnorm<fsqmat>; |
---|
57 | OM->set_parameters ( mat ( "1 0" ), zeros ( 1 ), fsqmat ( 1e-10*eye ( 1 ) ) ); |
---|
58 | OM->set_rv ( y ); |
---|
59 | OM->set_rvc ( x ); |
---|
60 | OM->validate(); |
---|
61 | |
---|
62 | StateDS sds; |
---|
63 | sds.set_parameters ( IM, OM ); |
---|
64 | sds.validate(); |
---|
65 | |
---|
66 | for ( int t = 1; t < 10; t++ ) { |
---|
67 | sds.write ( vec_1 ( double ( t ) ) ); |
---|
68 | // TODO ZDE TO SPADNE |
---|
69 | sds.step(); |
---|
70 | } |
---|
71 | |
---|
72 | vec dt; |
---|
73 | sds.getdata ( dt ); |
---|
74 | CHECK_CLOSE ( vec ( "94.5, 94.5, 13.5, 9" ), dt, 1e-2 ); |
---|
75 | } |
---|