Directory: | ./ |
---|---|
File: | tests/signal/test_dep.cpp |
Date: | 2024-12-13 12:22:33 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 64 | 68 | 94.1% |
Branches: | 91 | 194 | 46.9% |
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 | using namespace std; | ||
18 | using namespace dynamicgraph; | ||
19 | |||
20 | template <class Res = double> | ||
21 | class DummyClass { | ||
22 | public: | ||
23 |
1/2✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
12 | DummyClass(void) : res(), appel(0), timedata(0) {} |
24 | |||
25 | 6 | Res &fun(Res &res, int t) { | |
26 | 6 | appel++; | |
27 | 6 | timedata = t; | |
28 | |||
29 | 6 | cout << "Inside " << endl; | |
30 | 6 | for (list<SignalTimeDependent<double, int> *>::iterator it = | |
31 | 6 | inputsig.begin(); | |
32 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
6 | it != inputsig.end(); ++it) { |
33 | ✗ | cout << *(*it) << endl; | |
34 | ✗ | (*it)->access(timedata); | |
35 | } | ||
36 | 6 | for (list<SignalTimeDependent<dynamicgraph::Vector, int> *>::iterator it = | |
37 | 6 | inputsigV.begin(); | |
38 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
|
6 | it != inputsigV.end(); ++it) { |
39 | ✗ | cout << *(*it) << endl; | |
40 | ✗ | (*it)->access(timedata); | |
41 | } | ||
42 | |||
43 | 6 | return res = (*this)(); | |
44 | } | ||
45 | |||
46 | list<SignalTimeDependent<double, int> *> inputsig; | ||
47 | list<SignalTimeDependent<dynamicgraph::Vector, int> *> inputsigV; | ||
48 | |||
49 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | void add(SignalTimeDependent<double, int> &sig) { inputsig.push_back(&sig); } |
50 | 7 | void add(SignalTimeDependent<dynamicgraph::Vector, int> &sig) { | |
51 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | inputsigV.push_back(&sig); |
52 | 14 | } | |
53 | |||
54 | Res operator()(void); | ||
55 | |||
56 | Res res; | ||
57 | int appel; | ||
58 | int timedata; | ||
59 | }; | ||
60 | |||
61 | template <class Res> | ||
62 | Res DummyClass<Res>::operator()(void) { | ||
63 | return this->res; | ||
64 | } | ||
65 | |||
66 | template <> | ||
67 | 2 | double DummyClass<double>::operator()(void) { | |
68 | 2 | res = appel * timedata; | |
69 | 2 | return res; | |
70 | } | ||
71 | template <> | ||
72 | 1 | dynamicgraph::Vector DummyClass<dynamicgraph::Vector>::operator()(void) { | |
73 | 1 | res.resize(3); | |
74 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | res.fill(appel * timedata); |
75 | 1 | return res; | |
76 | } | ||
77 | |||
78 | // void dispArray( const SignalArray<int> &ar ) | ||
79 | // { | ||
80 | // for( unsigned int i=0;i<ar.rank;++i ) cout<<*ar.array[i]<<endl; | ||
81 | // } | ||
82 | |||
83 | #include <vector> | ||
84 | 1 | int main(void) { | |
85 | 1 | DummyClass<double> pro1, pro3, pro5; | |
86 |
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 | DummyClass<dynamicgraph::Vector> pro2, pro4, pro6; |
87 | |||
88 |
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"); |
89 |
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"); |
90 | |||
91 |
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"); |
92 | SignalTimeDependent<dynamicgraph::Vector, int> sig2( | ||
93 |
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"); |
94 |
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"); |
95 | SignalTimeDependent<double, int> sig1( | ||
96 |
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.
|
2 | boost::bind(&DummyClass<double>::fun, pro1, _1, _2), sig2 << sig3, |
97 |
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.
|
4 | "Sig1"); |
98 | |||
99 | // cout << "--- Test Array ------ "<<endl; | ||
100 | // SignalArray<int> tarr(12); | ||
101 | // tarr<<sig3<<sig2;//+sig2+sig3; | ||
102 | // dispArray(sig4<<sig2<<sig3); | ||
103 | // dispArray(tarr); | ||
104 | |||
105 | // sig1.set( &DummyClass<double>::fun,pro1 ); | ||
106 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | sig2.setFunction( |
107 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | boost::bind(&DummyClass<dynamicgraph::Vector>::fun, pro2, _1, _2)); |
108 |
4/8✓ 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.
|
1 | sig3.setFunction(boost::bind(&DummyClass<double>::fun, pro3, _1, _2)); |
109 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | sig4.setFunction( |
110 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | boost::bind(&DummyClass<dynamicgraph::Vector>::fun, pro4, _1, _2)); |
111 |
4/8✓ 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.
|
1 | sig5.setFunction(boost::bind(&DummyClass<double>::fun, pro5, _1, _2)); |
112 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | sig6.setFunction( |
113 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | boost::bind(&DummyClass<dynamicgraph::Vector>::fun, pro6, _1, _2)); |
114 | |||
115 | // sig1.addDependency(sig2); | ||
116 | // sig1.addDependency(sig3); | ||
117 | // sig2.addDependency(sig4); | ||
118 | // sig2.addDependency(sig4); | ||
119 | // sig2.addDependency(sig4); | ||
120 | // sig3.addDependency(sig2); | ||
121 | // sig4.addDependency(sig5); | ||
122 | // sig2.addDependency(sig6); | ||
123 | // sig3.addDependency(sig5); | ||
124 | // sig3.addDependency(sig6); | ||
125 | |||
126 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro1.add(sig2); |
127 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro1.add(sig3); |
128 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig4); |
129 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig4); |
130 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig4); |
131 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro3.add(sig2); |
132 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro4.add(sig5); |
133 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro2.add(sig6); |
134 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro3.add(sig5); |
135 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | pro3.add(sig6); |
136 | |||
137 | // sig5.setDependencyType(TimeDependency<int>::ALWAYS_READY); | ||
138 | // sig6.setDependencyType(TimeDependency<int>::BOOL_DEPENDENT); | ||
139 | |||
140 | 1 | sig6.setReady(); | |
141 | |||
142 |
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; |
143 | |||
144 |
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; |
145 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.access(2); |
146 |
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; |
147 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig2.access(4); |
148 |
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; |
149 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.access(4); |
150 |
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; |
151 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.needUpdate(6); |
152 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | sig1.needUpdate(6); |
153 | |||
154 | 1 | return 0; | |
155 | 1 | } | |
156 |