1 | #include "../bdm/stat/exp_family.h" |
---|
2 | #include "UnitTest++.h" |
---|
3 | |
---|
4 | using namespace bdm; |
---|
5 | |
---|
6 | TEST ( test_datalink ) { |
---|
7 | // RV names are global, and a, b and c are already taken by a |
---|
8 | // different test... |
---|
9 | RV a = RV ( "{dla }", "2" ); |
---|
10 | RV b = RV ( "{dlb }" ); |
---|
11 | RV c = RV ( "{dlc }" ); |
---|
12 | |
---|
13 | RV ab = a; |
---|
14 | ab.add ( b ); |
---|
15 | |
---|
16 | RV abc = ab; |
---|
17 | abc.add ( c ); |
---|
18 | |
---|
19 | datalink dl ( ab, abc ); |
---|
20 | vec total ( "0 37 42 66" ); |
---|
21 | vec filtered = dl.pushdown ( total ); |
---|
22 | int exp_f[] = { 0, 37, 42 }; |
---|
23 | int exp_sz = sizeof ( exp_f ) / sizeof ( exp_f[0] ); |
---|
24 | CHECK_EQUAL ( exp_sz, filtered.size() ); |
---|
25 | for ( int i = 0; i < exp_sz; ++i ) { |
---|
26 | CHECK_EQUAL ( exp_f[i], filtered ( i ) ); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | TEST ( test_datalink_m2e ) { |
---|
31 | RV a = RV ( "{dla }", "2" ); |
---|
32 | RV b = RV ( "{dlb }" ); |
---|
33 | RV c = RV ( "{dlc }" ); |
---|
34 | |
---|
35 | RV ab = a; |
---|
36 | ab.add ( b ); |
---|
37 | |
---|
38 | RV ba = a; |
---|
39 | ba.add ( b ); |
---|
40 | |
---|
41 | RV abc = ab; |
---|
42 | abc.add ( c ); |
---|
43 | |
---|
44 | datalink_m2e dl; |
---|
45 | dl.set_connection ( ba, c, abc ); |
---|
46 | vec total ( "0 37 42 66" ); |
---|
47 | vec cond = dl.get_cond ( total ); |
---|
48 | CHECK_EQUAL ( 1, cond.size() ); |
---|
49 | CHECK_EQUAL ( 66, cond ( 0 ) ); |
---|
50 | } |
---|
51 | |
---|
52 | TEST ( test_datalink_m2m ) { |
---|
53 | RV a = RV ( "{dla }", "2" ); |
---|
54 | RV b = RV ( "{dlb }" ); |
---|
55 | RV c = RV ( "{dlc }" ); |
---|
56 | |
---|
57 | datalink_m2m dl; |
---|
58 | dl.set_connection ( a, concat ( b, c ), concat ( a, b ), c ); |
---|
59 | |
---|
60 | vec val ( "1 1.5 2" ); |
---|
61 | vec cond ( "3" ); |
---|
62 | |
---|
63 | vec p = dl.pushdown ( val ); |
---|
64 | double exp_p[] = { 1.0, 1.5 }; |
---|
65 | int exp_sz = sizeof ( exp_p ) / sizeof ( exp_p[0] ); |
---|
66 | CHECK_EQUAL ( exp_sz, p.size() ); |
---|
67 | for ( int i = 0; i < exp_sz; ++i ) { |
---|
68 | CHECK_EQUAL ( exp_p[i], p ( i ) ); |
---|
69 | } |
---|
70 | |
---|
71 | vec dlcond = dl.get_cond ( val, cond ); |
---|
72 | int exp_c[] = { 2, 3 }; |
---|
73 | exp_sz = sizeof ( exp_c ) / sizeof ( exp_c[0] ); |
---|
74 | CHECK_EQUAL ( exp_sz, dlcond.size() ); |
---|
75 | for ( int i = 0; i < exp_sz; ++i ) { |
---|
76 | CHECK_EQUAL ( exp_c[i], dlcond ( i ) ); |
---|
77 | } |
---|
78 | } |
---|