12 | | int main() |
13 | | { |
14 | | RV a = RV ( "{a }","3"); |
15 | | RV b = RV ( "{b }","2"); |
16 | | RV c = RV ( "{c }"); |
17 | | RV ef = RV ("{e f }"); |
| 17 | RV b = RV("{b }", "2"); |
| 18 | CHECK_EQUAL(0, b.mint()); |
| 19 | |
| 20 | RV c = RV("{c }"); |
| 21 | CHECK_EQUAL(1, c.length()); |
| 22 | CHECK_EQUAL(1, c.size(0)); |
| 23 | |
| 24 | RV trv = RV("{e f }", "1 2", "3 4"); |
| 25 | CHECK_EQUAL(2, trv.length()); |
| 26 | CHECK_EQUAL(3, trv.mint()); |
| 27 | |
| 28 | // add a and b |
| 29 | RV ab = a; |
| 30 | bool added = ab.add(b); |
| 31 | CHECK(added); |
| 32 | CHECK_EQUAL(2, ab.length()); |
| 33 | CHECK_EQUAL(3, ab.size(0)); |
| 34 | CHECK_EQUAL(std::string("a"), ab.name(0)); |
| 35 | CHECK_EQUAL(2, ab.size(1)); |
| 36 | CHECK_EQUAL(std::string("b"), ab.name(1)); |
| 37 | |
| 38 | std::stringstream abss; |
| 39 | abss << ab; |
| 40 | CHECK_EQUAL(std::string("1(3)=a_{0}; 2(2)=b_{0}; "), abss.str()); |
| 41 | |
| 42 | // concat a, b and c |
| 43 | RV abc = concat(ab, c); |
| 44 | CHECK_EQUAL(3, abc.length()); |
| 45 | std::stringstream abcss; |
| 46 | abcss << abc; |
| 47 | CHECK_EQUAL(std::string("1(3)=a_{0}; 2(2)=b_{0}; 3(1)=c_{0}; "), abcss.str()); |
| 48 | |
| 49 | // structure of a, b, c |
| 50 | str s = abc.tostr(); |
| 51 | int exp_ids[] = { 1, 1, 1, 2, 2, 3 }; |
| 52 | int exp_sz = sizeof(exp_ids) / sizeof(exp_ids[0]); |
| 53 | CHECK_EQUAL(exp_sz, s.ids.size()); |
| 54 | CHECK_EQUAL(exp_sz, s.times.size()); |
| 55 | for (int i = 0; i < exp_sz; ++i) { |
| 56 | CHECK_EQUAL(exp_ids[i], s.ids(i)); |
| 57 | CHECK_EQUAL(0, s.times(i)); |
| 58 | } |
| 59 | |
| 60 | RV slice = abc(1, 2); |
| 61 | CHECK_EQUAL(1, slice.length()); |
| 62 | CHECK_EQUAL(3, slice.size(0)); |
| 63 | CHECK_EQUAL(std::string("a"), slice.name(0)); |
| 64 | |
| 65 | // find a in abc |
| 66 | ivec f = a.findself(abc); |
| 67 | CHECK_EQUAL(1, f.length()); |
| 68 | CHECK_EQUAL(0, f(0)); |
| 69 | |
| 70 | // find abc in a |
| 71 | f = abc.findself(a); |
| 72 | int exp_indices[] = { 0, -1, -1 }; |
| 73 | CHECK_EQUAL(3, f.length()); |
| 74 | for (unsigned i = 0; |
| 75 | i < sizeof(exp_indices) / sizeof(exp_indices[0]); |
| 76 | ++i) { |
| 77 | CHECK_EQUAL(exp_indices[i], f(i)); |
| 78 | } |
| 79 | |
| 80 | // subtract b from abc |
| 81 | RV ac = abc.subt(b); |
| 82 | std::stringstream acss; |
| 83 | acss << ac; |
| 84 | CHECK_EQUAL(std::string("1(3)=a_{0}; 3(1)=c_{0}; "), acss.str()); |
| 85 | |
| 86 | // data index of ac in abc |
| 87 | ivec di = ac.dataind(abc); |
| 88 | int exp_di[] = { 0, 1, 2, 5 }; |
| 89 | exp_sz = sizeof(exp_di) / sizeof(exp_di[0]); |
| 90 | CHECK_EQUAL(exp_sz, di.size()); |
| 91 | for (int i = 0; i < exp_sz; ++i) { |
| 92 | CHECK_EQUAL(exp_di[i], di(i)); |
| 93 | } |
| 94 | |
| 95 | // Copy indices between ba and ab |
| 96 | RV ba = b; |
| 97 | ba.add(a); |
19 | | cout << "Add a and b"<<endl; |
20 | | RV ab = a; |
21 | | ab.add(b); |
22 | | cout << ab <<endl; |
23 | | |
24 | | cout << "Concat a,b and c "<<endl; |
25 | | RV abc = concat(ab,c); |
26 | | cout << abc <<endl; |
27 | | cout << "Structure of a,b,c "<<endl; |
28 | | str s =abc.tostr(); |
29 | | cout << s.ids <<endl; |
30 | | cout << s.times <<endl; |
31 | | |
32 | | cout << "Find a in abc "<<endl; |
33 | | cout << a.findself(abc)<<endl; |
34 | | cout << "Find abc in a "<<endl; |
35 | | cout << abc.findself(a)<<endl; |
36 | | |
37 | | cout << "Subtract b from abc"<<endl; |
38 | | RV ac = abc.subt(b); |
39 | | cout << ac <<endl; |
40 | | |
41 | | cout << "Data index of ac in abc"<<endl; |
42 | | cout << ac.dataind(abc) <<endl; |
43 | | |
44 | | cout<< "copy indeces between ba and ab" << endl; |
45 | | RV ba = b; |
46 | | ba.add(a); |
47 | | |
48 | | ivec ai; |
49 | | ivec bi; |
50 | | ba.dataind(ac,ai,bi); |
51 | | cout << "ba(" << ai <<")=ac(" << bi <<")"<<endl; |
52 | | |
53 | | //Exit program: |
54 | | |
55 | | //getchar(); |
56 | | return 0; |
| 99 | ivec ai; |
| 100 | ivec bi; |
| 101 | ba.dataind(ac, ai, bi); |
| 103 | int exp_ai[] = { 2, 3, 4 }; |
| 104 | exp_sz = sizeof(exp_ai) / sizeof(exp_ai[0]); |
| 105 | CHECK_EQUAL(exp_sz, ai.size()); |
| 106 | for (unsigned i = 0; |
| 107 | i < sizeof(exp_ai) / sizeof(exp_ai[0]); |
| 108 | ++i) { |
| 109 | CHECK_EQUAL(exp_ai[i], ai(i)); |
| 110 | } |
| 111 | |
| 112 | int exp_bi[] = { 0, 1, 2 }; |
| 113 | exp_sz = sizeof(exp_bi) / sizeof(exp_bi[0]); |
| 114 | CHECK_EQUAL(exp_sz, bi.size()); |
| 115 | for (unsigned i = 0; |
| 116 | i < sizeof(exp_bi) / sizeof(exp_bi[0]); |
| 117 | ++i) { |
| 118 | CHECK_EQUAL(exp_bi[i], bi(i)); |
| 119 | } |