- Timestamp:
- 07/22/09 10:07:52 (16 years ago)
- Location:
- library
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
library/bdm/base/bdmbase.h
r422 r424 461 461 //! Remember how long val should be 462 462 int downsize; 463 463 464 //! Remember how long val of "Up" should be 464 465 int upsize; 465 //! val-to-val link, indeces of the upper val 466 467 //! val-to-val link, indices of the upper val 466 468 ivec v2v_up; 469 467 470 public: 468 471 //! Constructor 469 datalink() {}; 470 datalink(const RV &rv, const RV &rv_up) {set_connection(rv, rv_up);}; 472 datalink():downsize(0), upsize(0) { } 473 datalink(const RV &rv, const RV &rv_up) { set_connection(rv, rv_up); } 474 471 475 //! set connection, rv must be fully present in rv_up 472 476 void set_connection(const RV &rv, const RV &rv_up) { 473 477 downsize = rv._dsize(); 474 478 upsize = rv_up._dsize(); 475 v2v_up = (rv.dataind(rv_up));479 v2v_up = rv.dataind(rv_up); 476 480 477 481 it_assert_debug(v2v_up.length() == downsize, "rv is not fully in rv_up"); 478 482 } 479 //! set connection using indeces 483 484 //! set connection using indices 480 485 void set_connection(int ds, int us, const ivec &upind) { 481 486 downsize = ds; … … 485 490 it_assert_debug(v2v_up.length() == downsize, "rv is not fully in rv_up"); 486 491 } 492 487 493 //! Get val for myself from val of "Up" 488 494 vec pushdown(const vec &val_up) { … … 490 496 return get_vec(val_up, v2v_up); 491 497 } 498 492 499 //! Fill val of "Up" by my pieces 493 500 void pushup(vec &val_up, const vec &val) { … … 498 505 }; 499 506 500 //! data link between507 //! Data link with a condition. 501 508 class datalink_m2e: public datalink 502 509 { … … 504 511 //! Remember how long cond should be 505 512 int condsize; 506 //!upper_val-to-local_cond link, indeces of the upper val 513 514 //!upper_val-to-local_cond link, indices of the upper val 507 515 ivec v2c_up; 508 //!upper_val-to-local_cond link, ideces of the local cond 516 517 //!upper_val-to-local_cond link, indices of the local cond 509 518 ivec v2c_lo; 510 519 511 520 public: 512 datalink_m2e() {};513 521 //! Constructor 514 void set_connection(const RV &rv, const RV &rvc, const RV &rv_up) { 522 datalink_m2e():condsize(0) { } 523 524 void set_connection(const RV &rv, const RV &rvc, const RV &rv_up) { 515 525 datalink::set_connection(rv, rv_up); 516 condsize = 526 condsize = rvc._dsize(); 517 527 //establish v2c connection 518 528 rvc.dataind(rv_up, v2c_lo, v2c_up); 519 529 } 530 520 531 //!Construct condition 521 532 vec get_cond(const vec &val_up) { … … 524 535 return tmp; 525 536 } 537 526 538 void pushup_cond(vec &val_up, const vec &val, const vec &cond) { 527 539 it_assert_debug(downsize == val.length(), "Wrong val"); … … 531 543 } 532 544 }; 545 533 546 //!DataLink is a connection between mpdf and its superordinate (Up) 534 547 //! This class links … … 536 549 { 537 550 protected: 538 //!cond-to-cond link, ind eces of the upper cond551 //!cond-to-cond link, indices of the upper cond 539 552 ivec c2c_up; 540 //!cond-to-cond link, ind eces of the local cond553 //!cond-to-cond link, indices of the local cond 541 554 ivec c2c_lo; 555 542 556 public: 543 557 //! Constructor … … 549 563 it_assert_debug(c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given"); 550 564 } 565 551 566 //! Get cond for myself from val and cond of "Up" 552 567 vec get_cond(const vec &val_up, const vec &cond_up) { -
library/tests/CMakeLists.txt
r422 r424 11 11 12 12 # BASIC EXECS 13 EXEC(datalink_test)14 13 EXEC(loggers_test) 15 14 … … 41 40 42 41 # using UnitTest++ 43 add_executable(testsuite rv_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp)42 add_executable(testsuite datalink_test.cpp rv_test.cpp testsuite.cpp test_user_info.cpp test_shared_ptr.cpp) 44 43 target_link_libraries(testsuite bdm itpp unittest) 45 44 -
library/tests/datalink_test.cpp
r386 r424 1 #define BDMLIB // not an ideal way to prevent double registration of UI factories... 1 2 #include "../bdm/stat/exp_family.h" 3 #include "UnitTest++.h" 4 2 5 using namespace bdm; 3 6 4 int main() { 5 RV a = RV ( "{a }","2" ); 6 RV b = RV ( "{b }" ); 7 RV c = RV ( "{c }" ); 7 TEST(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 }"); 8 13 9 datalink_m2m dl;dl.set_connection ( a,concat(b,c),concat(a,b), c ); 14 RV ab = a; 15 ab.add(b); 10 16 11 vec val ( "1 1.5 2" );12 vec cond ( "3");17 RV abc = ab; 18 abc.add(c); 13 19 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 } 16 30 17 cout << "lo val: " << dl.pushdown ( val ) <<endl; 18 cout << "lo cond: " << dl.get_cond ( val,cond ) <<endl; 31 TEST(test_datalink_m2e) { 32 RV a = RV("{dla }", "2"); 33 RV b = RV("{dlb }"); 34 RV c = RV("{dlc }"); 19 35 20 //getchar();21 return 0;36 RV ab = a; 37 ab.add(b); 22 38 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)); 23 51 } 52 53 TEST(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 }