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 
94 
96  std::istringstream iss("empty");
97  res = false;
98  try {
99  sigB.set(iss);
100  } catch (const ExceptionSignal &aea) {
101  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
102  }
103  BOOST_CHECK(res);
104 
106  res = false;
107  std::ostringstream oss;
108  try {
109  sigB.get(oss);
110  } catch (const ExceptionSignal &aea) {
111  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
112  }
113  BOOST_CHECK(res);
114 
116  res = false;
117  try {
118  sigB.recompute(100);
119  } catch (const ExceptionSignal &aea) {
120  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
121  }
122  BOOST_CHECK(res);
123 
125  res = false;
126  try {
127  sigB.trace(oss);
128  } catch (const ExceptionSignal &aea) {
129  res = (aea.getCode() == ExceptionSignal::SET_IMPOSSIBLE);
130  }
131  BOOST_CHECK(res);
132 
134  sigB.display(output);
135  BOOST_CHECK(output.is_equal("Sig:test"));
136 }
137 
138 BOOST_AUTO_TEST_CASE(test_cast_helper) {
139  std::istringstream iss;
140  iss.str("1");
142 
143  {
144  std::istringstream iss_fail;
145  iss.str("test");
146  BOOST_CHECK_THROW(signal_io<int>::cast(iss_fail), ExceptionSignal);
147  }
148 
150  output_test_stream output;
152  avec.resize(4);
153  avec[0] = 1.0;
154  avec[1] = 2.0;
155  avec[2] = 3.0;
156  avec[3] = 4.0;
157  BOOST_CHECK_NO_THROW(signal_io<Vector>::trace(avec, output));
158 
160  dynamicgraph::Matrix amatrix;
161  amatrix.resize(2, 2);
162  amatrix(0, 0) = 0.0;
163  amatrix(0, 1) = 1.0;
164  amatrix(1, 0) = 2.0;
165  amatrix(1, 1) = 3.0;
166  BOOST_CHECK_NO_THROW(signal_io<Matrix>::trace(amatrix, output));
167 
168  std::istringstream aiss("test");
170 }
signal-array.h
dynamicgraph::SignalBase::recompute
virtual void recompute(const Time &)
Definition: signal-base.h:135
dynamicgraph::SignalBase::setPeriodTime
virtual void setPeriodTime(const Time &)
Definition: signal-base.h:48
dynamicgraph
dynamicgraph::command
Definition: command-bind.h:31
dynamicgraph::SignalBase::setConstantDefault
virtual void setConstantDefault()
Definition: signal-base.h:106
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
Definition: linear-algebra.h:13
dynamicgraph::SignalArray_const
TODO.
Definition: fwd.hh:50
dynamicgraph::SignalBase::display
virtual std::ostream & display(std::ostream &os) const
Definition: signal-base.h:154
tracer.h
dynamicgraph::SignalBase::get
virtual void get(std::ostream &) const
Definition: signal-base.h:128
dynamicgraph::SignalBase::set
virtual void set(std::istringstream &)
Definition: signal-base.h:121
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_array)
Definition: signal-all.cpp:31
sig
dynamicgraph::SignalArray_const< double > sig
Definition: signal-all.cpp:25
dynamicgraph::SignalBase::plug
virtual void plug(SignalBase< Time > *sigarg)
Definition: signal-base.h:87
dynamicgraph::ExceptionAbstract::getCode
int getCode() const
Access to the error code.
Definition: exception-abstract.cpp:24
dynamicgraph::signal_io
Class used for I/O operations in Signal<T,Time>
Definition: signal-caster.h:56
dynamicgraph::SignalBase::unplug
virtual void unplug()
Definition: signal-base.h:95
dynamicgraph::Vector
Eigen::VectorXd Vector
Definition: linear-algebra.h:14
dynamicgraph::SignalBase::addDependency
virtual void addDependency(const SignalBase< Time > &)
Definition: signal-base.h:57
factory.h
dynamicgraph::ExceptionSignal
Exceptions raised when an error related to signals happen.
Definition: exception-signal.h:19
dynamicgraph::SignalBase::removeDependency
virtual void removeDependency(const SignalBase< Time > &)
Definition: signal-base.h:59
dynamicgraph::SignalBase::needUpdate
virtual bool needUpdate(const Time &) const
Definition: signal-base.h:63
dynamicgraph::SignalArray_const::getSize
virtual unsigned int getSize() const
Definition: signal-array.h:72
dynamicgraph::SignalBase::writeGraph
virtual std::ostream & writeGraph(std::ostream &os) const
Definition: signal-base.h:67
dynamicgraph::SignalArray
TODO.
Definition: fwd.hh:47
dynamicgraph::SignalBase::trace
virtual void trace(std::ostream &) const
Definition: signal-base.h:142
dynamicgraph::SignalBase
The base class for signals: not to be used as such.
Definition: fwd.hh:53
dynamicgraph::SignalBase::clearDependencies
virtual void clearDependencies()
Definition: signal-base.h:61
dynamicgraph::SignalBase::getReady
const bool & getReady() const
Definition: signal-base.h:40
dynamicgraph::SignalBase::getPeriodTime
virtual Time getPeriodTime() const
Definition: signal-base.h:50
debug.h
signal-caster.h
dynamicgraph::SignalBase::setReady
void setReady(const bool sready=true)
Definition: signal-base.h:65


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38