| Directory: | ./ |
|---|---|
| File: | tests/signal/test_depend.cpp |
| Date: | 2025-05-13 12:28:21 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 67 | 67 | 100.0% |
| Branches: | 102 | 200 | 51.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright 2010, | ||
| 3 | * François Bleibel, | ||
| 4 | * Olivier Stasse, | ||
| 5 | * | ||
| 6 | * CNRS/AIST | ||
| 7 | * | ||
| 8 | */ | ||
| 9 | |||
| 10 | /* -------------------------------------------------------------------------- */ | ||
| 11 | /* --- INCLUDES ------------------------------------------------------------- */ | ||
| 12 | /* -------------------------------------------------------------------------- */ | ||
| 13 | #include <dynamic-graph/all-signals.h> | ||
| 14 | #include <dynamic-graph/linear-algebra.h> | ||
| 15 | |||
| 16 | #include <iostream> | ||
| 17 | #include <sot/core/debug.hh> | ||
| 18 | |||
| 19 | using namespace std; | ||
| 20 | using namespace dynamicgraph; | ||
| 21 | |||
| 22 | template <class Res = double> | ||
| 23 | class DummyClass { | ||
| 24 | public: | ||
| 25 | std::string proname; | ||
| 26 | list<SignalTimeDependent<double, int> *> inputsig; | ||
| 27 | list<SignalTimeDependent<dynamicgraph::Vector, int> *> inputsigV; | ||
| 28 | |||
| 29 | public: | ||
| 30 |
1/2✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
12 | DummyClass(const std::string &n) : proname(n), res(), appel(0), timedata(0) {} |
| 31 | |||
| 32 | 26 | Res &fun(Res &res, int t) { | |
| 33 | 26 | appel++; | |
| 34 | 26 | timedata = t; | |
| 35 | |||
| 36 | 26 | cout << "Inside " << proname << " -> " << this << endl; | |
| 37 | 26 | for (list<SignalTimeDependent<double, int> *>::iterator it = | |
| 38 | 26 | inputsig.begin(); | |
| 39 |
2/2✓ Branch 3 taken 6 times.
✓ Branch 4 taken 13 times.
|
38 | it != inputsig.end(); ++it) { |
| 40 |
2/4✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
|
12 | cout << *(*it) << endl; |
| 41 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | (*it)->access(timedata); |
| 42 | } | ||
| 43 | 26 | for (list<SignalTimeDependent<dynamicgraph::Vector, int> *>::iterator it = | |
| 44 | 26 | inputsigV.begin(); | |
| 45 |
2/2✓ Branch 3 taken 14 times.
✓ Branch 4 taken 13 times.
|
54 | it != inputsigV.end(); ++it) { |
| 46 |
2/4✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
|
28 | cout << *(*it) << endl; |
| 47 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
28 | (*it)->access(timedata); |
| 48 | } | ||
| 49 | |||
| 50 | 26 | return res = (*this)(); | |
| 51 | } | ||
| 52 | |||
| 53 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | void add(SignalTimeDependent<double, int> &sig) { inputsig.push_back(&sig); } |
| 54 | 7 | void add(SignalTimeDependent<dynamicgraph::Vector, int> &sig) { | |
| 55 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | inputsigV.push_back(&sig); |
| 56 | 14 | } | |
| 57 | |||
| 58 | Res operator()(void); | ||
| 59 | |||
| 60 | Res res; | ||
| 61 | int appel; | ||
| 62 | int timedata; | ||
| 63 | }; | ||
| 64 | |||
| 65 | template <class Res> | ||
| 66 | Res DummyClass<Res>::operator()(void) { | ||
| 67 | return this->res; | ||
| 68 | } | ||
| 69 | |||
| 70 | template <> | ||
| 71 | 8 | double DummyClass<double>::operator()(void) { | |
| 72 | 8 | res = appel * timedata; | |
| 73 | 8 | return res; | |
| 74 | } | ||
| 75 | template <> | ||
| 76 | 5 | dynamicgraph::Vector DummyClass<dynamicgraph::Vector>::operator()(void) { | |
| 77 | 5 | res.resize(3); | |
| 78 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | res.fill(appel * timedata); |
| 79 | 5 | return res; | |
| 80 | } | ||
| 81 | |||
| 82 | 1 | int main(void) { | |
| 83 |
6/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
4 | DummyClass<double> pro1("pro1"), pro3("pro3"), pro5("pro5"); |
| 84 |
6/12✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
|
4 | DummyClass<dynamicgraph::Vector> pro2("pro2"), pro4("pro4"), pro6("pro6"); |
| 85 | |||
| 86 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | SignalTimeDependent<double, int> sig5("Sig5"); |
| 87 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
|
2 | SignalTimeDependent<dynamicgraph::Vector, int> sig6("Sig6"); |
| 88 | |||
| 89 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
2 | SignalTimeDependent<dynamicgraph::Vector, int> sig4(sig5, "Sig4"); |
| 90 | SignalTimeDependent<dynamicgraph::Vector, int> sig2( | ||
| 91 |
5/10✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
|
2 | sig4 << sig4 << sig4 << sig6, "Sig2"); |
| 92 |
4/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
2 | SignalTimeDependent<double, int> sig3(sig2 << sig5 << sig6, "Sig3"); |
| 93 | SignalTimeDependent<double, int> sig1( | ||
| 94 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | boost::bind(&DummyClass<double>::fun, &pro1, _1, _2), sig2 << sig3, |
| 95 |
4/8✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
4 | "Sig1"); |
| 96 | |||
| 97 | // cout << "--- Test Array ------ "<<endl; | ||
| 98 | // SignalArray<int> tarr(12); | ||
| 99 | // tarr<<sig3<<sig2;//+sig2+sig3; | ||
| 100 | // dispArray(sig4<<sig2<<sig3); | ||
| 101 | // dispArray(tarr); | ||
| 102 | |||
| 103 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | sig2.setFunction( |
| 104 | boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro2, _1, _2)); | ||
| 105 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | sig3.setFunction(boost::bind(&DummyClass<double>::fun, &pro3, _1, _2)); |
| 106 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | sig4.setFunction( |
| 107 | boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro4, _1, _2)); | ||
| 108 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | sig5.setFunction(boost::bind(&DummyClass<double>::fun, &pro5, _1, _2)); |
| 109 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | sig6.setFunction( |
| 110 | boost::bind(&DummyClass<dynamicgraph::Vector>::fun, &pro6, _1, _2)); | ||
| 111 | |||
| 112 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro1.add(sig2); |
| 113 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro1.add(sig3); |
| 114 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig4); |
| 115 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig4); |
| 116 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig4); |
| 117 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro3.add(sig2); |
| 118 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro4.add(sig5); |
| 119 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig6); |
| 120 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro3.add(sig5); |
| 121 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro3.add(sig6); |
| 122 | |||
| 123 | 1 | sig5.setDependencyType(TimeDependency<int>::ALWAYS_READY); | |
| 124 | 1 | sig6.setDependencyType(TimeDependency<int>::BOOL_DEPENDENT); | |
| 125 | |||
| 126 | 1 | sig6.setReady(); | |
| 127 | |||
| 128 |
5/10✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
|
1 | sig1.displayDependencies(cout) << endl; |
| 129 | |||
| 130 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
1 | cout << "Needs update?" << endl << sig1.needUpdate(2) << endl; |
| 131 | dgDEBUG(1) << "Access sig1(2) " << endl; | ||
| 132 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.access(2); |
| 133 |
5/10✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
|
1 | sig1.displayDependencies(cout) << endl; |
| 134 | dgDEBUG(1) << "Access sig2(4) " << endl; | ||
| 135 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig2.access(4); |
| 136 |
5/10✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
|
1 | sig1.displayDependencies(cout) << endl; |
| 137 | dgDEBUG(1) << "Access sig1(4) " << endl; | ||
| 138 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.access(4); |
| 139 |
5/10✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 1 times.
✗ Branch 17 not taken.
|
1 | sig1.displayDependencies(cout) << endl; |
| 140 | |||
| 141 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.needUpdate(6); |
| 142 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.needUpdate(6); |
| 143 | |||
| 144 | 1 | return 0; | |
| 145 | 1 | } | |
| 146 |