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