signal-all.cpp
Go to the documentation of this file.
1 //
2 // Created by corentin on 7/3/19.
3 //
4 
5 #include <assert.h>
6 #include <dynamic-graph/debug.h>
10 #include <dynamic-graph/tracer.h>
11 
12 #include <boost/foreach.hpp>
13 #if BOOST_VERSION >= 105900
14 #include <boost/test/tools/output_test_stream.hpp>
15 #else
16 #include <boost/test/output_test_stream.hpp>
17 #endif
18 #include <boost/test/unit_test.hpp>
19 #include <iostream>
20 
21 #define BOOST_TEST_MODULE signal_array
22 
23 using boost::test_tools::output_test_stream;
24 
26 
27 using namespace std;
28 using namespace dynamicgraph;
29 using namespace dynamicgraph::command;
30 
31 BOOST_AUTO_TEST_CASE(test_array) {
32  SignalBase<int> sigBa("add test");
33  SignalArray_const<int> sigArr_C(1);
34  sigArr_C.operator<<(sigBa);
35  sigArr_C.operator<<(sigBa);
36  BOOST_CHECK_EQUAL(2, sigArr_C.getSize());
37 
38  SignalArray<int> sigArr(1);
39  sigArr.operator<<(sigBa);
40  sigArr.operator<<(sigBa);
41  BOOST_CHECK_EQUAL(2, sigArr.getSize());
42 
43  SignalBase<int> sigB("constructor test");
44  SignalArray<int> sigA(2);
45  sigA << sigB;
46  sigA.operator<<(sigB);
47  SignalArray_const<int> sig_C(sigA);
48  BOOST_CHECK_EQUAL(sigA.getSize(), sig_C.getSize());
49 }
50 
52  SignalBase<int> sigA("testA");
53  SignalBase<int> sigB("test");
54  sigB.setReady();
55  BOOST_CHECK_EQUAL(true, sigB.getReady());
56  // Does nothing, just check that the interface
57  // still exist at the abstract level.
58  sigB.setPeriodTime(1);
59  sigB.getPeriodTime();
60  sigB.addDependency(sigA);
61  sigB.removeDependency(sigA);
62  sigB.clearDependencies();
63  BOOST_CHECK_EQUAL(true, sigB.needUpdate(10));
64  output_test_stream output;
65  sigB.writeGraph(output);
66  BOOST_CHECK(output.is_equal(""));
67 
69  bool res = false;
70  try {
71  sigB.plug(&sigA);
72  } catch (const ExceptionSignal &aea) {
73  res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
74  }
75  BOOST_CHECK(res);
76 
77  res = false;
78  try {
79  sigB.unplug();
80  } catch (const ExceptionSignal &aea) {
81  res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
82  }
83  BOOST_CHECK(res);
84 
85  res = false;
86  try {
87  sigB.setConstantDefault();
88  } catch (const ExceptionSignal &aea) {
89  res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
90  }
91  BOOST_CHECK(res);
92 
93  res = false;
94  try {
96  sigB.checkCompatibility();
97  } catch (const ExceptionSignal &aea) {
98  res = (aea.getCode() == ExceptionSignal::PLUG_IMPOSSIBLE);
99  }
101 
103  std::istringstream iss("empty");
104  res = false;
105  try {
106  sigB.set(iss);
107  } catch (const ExceptionSignal &aea) {
108  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
109  }
110  BOOST_CHECK(res);
111 
113  res = false;
114  std::ostringstream oss;
115  try {
116  sigB.get(oss);
117  } catch (const ExceptionSignal &aea) {
118  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
119  }
120  BOOST_CHECK(res);
121 
123  res = false;
124  try {
125  sigB.recompute(100);
126  } catch (const ExceptionSignal &aea) {
127  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
128  }
129  BOOST_CHECK(res);
130 
132  res = false;
133  try {
134  sigB.trace(oss);
135  } catch (const ExceptionSignal &aea) {
136  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
137  }
138  BOOST_CHECK(res);
139 
141  sigB.display(output);
142  BOOST_CHECK(output.is_equal("Sig:test"));
143 }
144 
145 BOOST_AUTO_TEST_CASE(test_cast_helper) {
146  std::istringstream iss;
147  iss.str("1");
149 
150  {
151  std::istringstream iss_fail;
152  iss.str("test");
153  BOOST_CHECK_THROW(signal_io<int>::cast(iss_fail), ExceptionSignal);
154  }
155 
157  output_test_stream output;
159  avec.resize(4);
160  avec[0] = 1.0;
161  avec[1] = 2.0;
162  avec[2] = 3.0;
163  avec[3] = 4.0;
164  BOOST_CHECK_NO_THROW(signal_io<Vector>::trace(avec, output));
165 
167  dynamicgraph::Matrix amatrix;
168  amatrix.resize(2, 2);
169  amatrix(0, 0) = 0.0;
170  amatrix(0, 1) = 1.0;
171  amatrix(1, 0) = 2.0;
172  amatrix(1, 1) = 3.0;
173  BOOST_CHECK_NO_THROW(signal_io<Matrix>::trace(amatrix, output));
174 
175  std::istringstream aiss("test");
177 }
virtual void trace(std::ostream &) const
Definition: signal-base.h:142
virtual Time getPeriodTime() const
Definition: signal-base.h:50
Eigen::VectorXd Vector
virtual void setConstantDefault()
Definition: signal-base.h:106
virtual void recompute(const Time &)
Definition: signal-base.h:135
virtual void setPeriodTime(const Time &)
Definition: signal-base.h:48
Class used for I/O operations in Signal<T,Time>
Definition: signal-caster.h:56
dynamicgraph::SignalArray_const< double > sig
Definition: signal-all.cpp:25
Exceptions raised when an error related to signals happen.
virtual void get(std::ostream &) const
Definition: signal-base.h:128
virtual void set(std::istringstream &)
Definition: signal-base.h:121
int getCode() const
Access to the error code.
virtual void checkCompatibility()
Definition: signal-base.h:191
virtual std::ostream & display(std::ostream &os) const
Definition: signal-base.h:154
virtual unsigned int getSize() const
Definition: signal-array.h:72
BOOST_AUTO_TEST_CASE(test_array)
Definition: signal-all.cpp:31
virtual void addDependency(const SignalBase< Time > &)
Definition: signal-base.h:57
virtual void plug(SignalBase< Time > *sigarg)
Definition: signal-base.h:87
virtual void unplug()
Definition: signal-base.h:95
Eigen::MatrixXd Matrix
virtual bool needUpdate(const Time &) const
Definition: signal-base.h:63
virtual void clearDependencies()
Definition: signal-base.h:61
virtual std::ostream & writeGraph(std::ostream &os) const
Definition: signal-base.h:67
void setReady(const bool sready=true)
Definition: signal-base.h:65
virtual void removeDependency(const SignalBase< Time > &)
Definition: signal-base.h:59
const bool & getReady() const
Definition: signal-base.h:40


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03