Changeset 424 for library/tests

Show
Ignore:
Timestamp:
07/22/09 10:07:52 (15 years ago)
Author:
vbarta
Message:

moved datalink tests to testsuite, added default initialization to datalink classes

Location:
library/tests
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • library/tests/CMakeLists.txt

    r422 r424  
    1111 
    1212# BASIC EXECS 
    13 EXEC(datalink_test) 
    1413EXEC(loggers_test) 
    1514 
     
    4140 
    4241# using UnitTest++ 
    43 add_executable(testsuite rv_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp) 
     42add_executable(testsuite datalink_test.cpp rv_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp) 
    4443target_link_libraries(testsuite bdm itpp unittest) 
    4544 
  • library/tests/datalink_test.cpp

    r386 r424  
     1#define BDMLIB // not an ideal way to prevent double registration of UI factories... 
    12#include "../bdm/stat/exp_family.h" 
     3#include "UnitTest++.h" 
     4 
    25using namespace bdm; 
    36 
    4 int main() { 
    5         RV a = RV ( "{a }","2" ); 
    6         RV b = RV ( "{b }" ); 
    7         RV c = RV ( "{c }" ); 
     7TEST(test_datalink) { 
     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 }"); 
    813 
    9         datalink_m2m dl;dl.set_connection ( a,concat(b,c),concat(a,b), c ); 
     14    RV ab = a; 
     15    ab.add(b); 
    1016 
    11         vec val ( "1 1.5 2" ); 
    12         vec cond ( "3" ); 
     17    RV abc = ab; 
     18    abc.add(c); 
    1319 
    14         cout << "val: " << val  << endl; 
    15         cout << "cond: " << cond  << endl; 
     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} 
    1630 
    17         cout << "lo val: " << dl.pushdown ( val ) <<endl; 
    18         cout << "lo cond: " << dl.get_cond ( val,cond ) <<endl; 
     31TEST(test_datalink_m2e) { 
     32    RV a = RV("{dla }", "2"); 
     33    RV b = RV("{dlb }"); 
     34    RV c = RV("{dlc }"); 
    1935 
    20         //getchar(); 
    21         return 0; 
     36    RV ab = a; 
     37    ab.add(b); 
    2238 
     39    RV ba = a; 
     40    ba.add(b); 
     41 
     42    RV abc = ab; 
     43    abc.add(c); 
     44 
     45    datalink_m2e dl; 
     46    dl.set_connection(ba, c, abc); 
     47    vec total("0 37 42 66"); 
     48    vec cond = dl.get_cond(total); 
     49    CHECK_EQUAL(1, cond.size()); 
     50    CHECK_EQUAL(66, cond(0)); 
    2351} 
     52 
     53TEST(test_datalink_m2m) { 
     54    RV a = RV("{dla }", "2"); 
     55    RV b = RV("{dlb }"); 
     56    RV c = RV("{dlc }"); 
     57 
     58    datalink_m2m dl; 
     59    dl.set_connection(a, concat(b, c), concat(a, b), c); 
     60 
     61    vec val("1 1.5 2"); 
     62    vec cond("3"); 
     63 
     64    vec p = dl.pushdown(val); 
     65    double exp_p[] = { 1.0, 1.5 }; 
     66    int exp_sz = sizeof(exp_p) / sizeof(exp_p[0]); 
     67    CHECK_EQUAL(exp_sz, p.size()); 
     68    for (int i = 0; i < exp_sz; ++i) { 
     69        CHECK_EQUAL(exp_p[i], p(i)); 
     70    } 
     71 
     72    vec dlcond = dl.get_cond(val, cond); 
     73    int exp_c[] = { 2, 3 }; 
     74    exp_sz = sizeof(exp_c) / sizeof(exp_c[0]); 
     75    CHECK_EQUAL(exp_sz, dlcond.size()); 
     76    for (int i = 0; i < exp_sz; ++i) { 
     77        CHECK_EQUAL(exp_c[i], dlcond(i)); 
     78    } 
     79}