Directory: | ./ |
---|---|
File: | tests/signal/test_signal.cpp |
Date: | 2024-11-13 12:35:17 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 26 | 100.0% |
Branches: | 31 | 62 | 50.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 | using namespace std; | ||
18 | using namespace dynamicgraph; | ||
19 | |||
20 | class DummyClass { | ||
21 | public: | ||
22 | 2 | dynamicgraph::Vector &fun(dynamicgraph::Vector &res, double j) { | |
23 | 2 | res.resize(3); | |
24 | 2 | res.fill(j); | |
25 | 2 | return res; | |
26 | } | ||
27 | }; | ||
28 | |||
29 | dynamicgraph::Vector test_data(6); | ||
30 | Signal<dynamicgraph::Vector, double> sig("sigtest"); | ||
31 | DummyClass dummy; | ||
32 | |||
33 | 2 | dynamicgraph::Vector &fun(dynamicgraph::Vector &res, double /*j*/) { | |
34 | 2 | return res = test_data; | |
35 | } | ||
36 | |||
37 | 1 | int main(void) { | |
38 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | test_data.fill(1); |
39 | 1 | cout << "test_data: " << test_data << endl; | |
40 | |||
41 | 1 | sig.setConstant(test_data); | |
42 |
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.
|
1 | cout << "Constant: " << sig.access(1.) << endl; |
43 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | test_data *= 2; |
44 |
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.
|
1 | cout << "Constant: " << sig(1.) << endl; |
45 | |||
46 | 1 | sig.setReference(&test_data); | |
47 |
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.
|
1 | cout << "Reference: " << sig(1.) << endl; |
48 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | test_data *= 2; |
49 |
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.
|
1 | cout << "Reference: " << sig(1.) << endl; |
50 | |||
51 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | sig.setFunction(&fun); |
52 |
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.
|
1 | cout << "Function: " << sig(1.) << endl; |
53 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | test_data *= 2; |
54 |
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.
|
1 | cout << "Function: " << sig(1.) << endl; |
55 | |||
56 | // boost::function2<int,int,double> onClick = (&DummyClass::fun, &dummy, | ||
57 | // _1,_2) ; boost::function<> onClick = boost::bind(&DummyClass::fun, | ||
58 | // &dummy); | ||
59 |
1/2✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
|
1 | sig.setFunction(boost::bind(&DummyClass::fun, &dummy, _1, _2)); |
60 |
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.
|
1 | cout << "Function: " << sig(1.5) << endl; |
61 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | test_data *= 2; |
62 |
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.
|
1 | cout << "Function: " << sig(1.34) << endl; |
63 | |||
64 | // sig.setFunction(&DummyClass::fun, dummy); | ||
65 | // cout << "Function: " << sig(1.5) <<endl; | ||
66 | // test_data*=2; | ||
67 | // cout << "Function: " << sig(12.34) <<endl; | ||
68 | |||
69 | 1 | return 0; | |
70 | } | ||
71 |