1 | #include "../bdm/stat/exp_family.h" |
---|
2 | #include "../mat_checks.h" |
---|
3 | #include "UnitTest++.h" |
---|
4 | |
---|
5 | using namespace bdm; |
---|
6 | |
---|
7 | TEST ( datalink_test ) { |
---|
8 | // RV names are global, and a, b and c are already taken by a |
---|
9 | // different test... |
---|
10 | RV a = RV ( "{dla }", "2" ); |
---|
11 | RV b = RV ( "{dlb }" ); |
---|
12 | RV c = RV ( "{dlc }" ); |
---|
13 | |
---|
14 | RV ab = a; |
---|
15 | ab.add ( b ); |
---|
16 | |
---|
17 | RV abc = ab; |
---|
18 | abc.add ( c ); |
---|
19 | |
---|
20 | datalink dl ( ab, abc ); |
---|
21 | vec total ( "0 37 42 66" ); |
---|
22 | vec filtered = dl.pushdown ( total ); |
---|
23 | int exp_f[] = { 0, 37, 42 }; |
---|
24 | int exp_sz = sizeof ( exp_f ) / sizeof ( exp_f[0] ); |
---|
25 | CHECK_EQUAL ( exp_sz, filtered.size() ); |
---|
26 | for ( int i = 0; i < exp_sz; ++i ) { |
---|
27 | CHECK_EQUAL ( exp_f[i], filtered ( i ) ); |
---|
28 | } |
---|
29 | |
---|
30 | datalink unnamed; |
---|
31 | unnamed.set_connection ( 1, 2, ivec ( "0" ) ); |
---|
32 | filtered = unnamed.pushdown ( vec ( "37 42" ) ); |
---|
33 | CHECK_EQUAL ( vec ( "37" ), filtered ); |
---|
34 | } |
---|
35 | |
---|
36 | TEST ( datalink_m2e_test ) { |
---|
37 | RV a = RV ( "{dla }", "2" ); |
---|
38 | RV b = RV ( "{dlb }" ); |
---|
39 | RV c = RV ( "{dlc }" ); |
---|
40 | |
---|
41 | RV ab = a; |
---|
42 | ab.add ( b ); |
---|
43 | |
---|
44 | RV ba = a; |
---|
45 | ba.add ( b ); |
---|
46 | |
---|
47 | RV abc = ab; |
---|
48 | abc.add ( c ); |
---|
49 | |
---|
50 | datalink_m2e dl; |
---|
51 | dl.set_connection ( ba, c, abc ); |
---|
52 | vec total ( "0 37 42 66" ); |
---|
53 | vec cond = dl.get_cond ( total ); |
---|
54 | CHECK_EQUAL ( 1, cond.size() ); |
---|
55 | CHECK_EQUAL ( 66, cond ( 0 ) ); |
---|
56 | |
---|
57 | vec big ( 4 ); |
---|
58 | dl.pushup_cond ( big, vec ( "2 3 5" ), vec ( "7" ) ); |
---|
59 | CHECK_EQUAL ( vec ( "2 3 5 7" ), big ); |
---|
60 | } |
---|
61 | |
---|
62 | TEST ( datalink_m2m_test ) { |
---|
63 | RV a = RV ( "{dla }", "2" ); |
---|
64 | RV b = RV ( "{dlb }" ); |
---|
65 | RV c = RV ( "{dlc }" ); |
---|
66 | |
---|
67 | datalink_m2m dl; |
---|
68 | dl.set_connection ( a, concat ( b, c ), concat ( a, b ), c ); |
---|
69 | |
---|
70 | vec val ( "1 1.5 2" ); |
---|
71 | vec cond ( "3" ); |
---|
72 | |
---|
73 | vec p = dl.pushdown ( val ); |
---|
74 | double exp_p[] = { 1.0, 1.5 }; |
---|
75 | int exp_sz = sizeof ( exp_p ) / sizeof ( exp_p[0] ); |
---|
76 | CHECK_EQUAL ( exp_sz, p.size() ); |
---|
77 | for ( int i = 0; i < exp_sz; ++i ) { |
---|
78 | CHECK_EQUAL ( exp_p[i], p ( i ) ); |
---|
79 | } |
---|
80 | |
---|
81 | vec dlcond = dl.get_cond ( val, cond ); |
---|
82 | int exp_c[] = { 2, 3 }; |
---|
83 | exp_sz = sizeof ( exp_c ) / sizeof ( exp_c[0] ); |
---|
84 | CHECK_EQUAL ( exp_sz, dlcond.size() ); |
---|
85 | for ( int i = 0; i < exp_sz; ++i ) { |
---|
86 | CHECK_EQUAL ( exp_c[i], dlcond ( i ) ); |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | TEST ( datalink_buffered_test ) { |
---|
91 | RV a = RV ( "{dl_a }" ); |
---|
92 | RV b = RV ( "{dlb }" ); |
---|
93 | RV ab = concat ( a, b ); |
---|
94 | RV aa = a; |
---|
95 | a.t_plus ( -1 ); |
---|
96 | aa.add ( a ); |
---|
97 | |
---|
98 | |
---|
99 | datalink_buffered dl; |
---|
100 | dl.set_connection ( concat ( aa, b ), ab ); |
---|
101 | |
---|
102 | vec val_up ( "1 2" ); |
---|
103 | dl.store_data(val_up); |
---|
104 | val_up = "3 4"; |
---|
105 | |
---|
106 | |
---|
107 | vec p = dl.pushdown ( val_up ); |
---|
108 | vec exp_p = " 3, 1, 4 "; |
---|
109 | CHECK_EQUAL ( exp_p, p ); |
---|
110 | |
---|
111 | } |
---|