EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SumBlockTest.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_TEST_CONTROL_SUMBLOCKTEST_HPP_
2 #define ORG_EEROS_TEST_CONTROL_SUMBLOCKTEST_HPP_
4 #include <eeros/control/Sum.hpp>
5 
6 #include <iostream>
7 #include <fstream>
8 
9 #include "../../Utils.hpp"
10 
11 template <unsigned int I, typename T>
13  public:
15  for (int i = 0; i < I; i++) {
16  uut.getIn(i).connect(data[i]);
17  }
18  }
19 
20  int run(const char* filepath) {
21  std::ifstream file(filepath);
22  if (!file.is_open()) return -2;
23 
24  int line = 0;
25  int error = 0;
26 
27  while (!file.eof()) {
28  line++;
29  for (int i = 0; i < I; i++) {
30  double in;
31  file >> in; // read input data
32  data[i].getSignal().setValue(in);
33  }
34  if (file.eof()) break;
35  double out;
36  file >> out; // read reference result
37  uut.run();
38 
39  if(!Utils::compareApprox(out, uut.getOut().getSignal().getValue(), 0.001)) {
40  error++;
41  std::cout << "line " << line << " expecting " << out << " calculated " << uut.getOut().getSignal().getValue() << std::endl;
42  }
43  }
44 
45  file.close();
46  return error;
47  }
48 
49  protected:
52 };
53 
54 template <unsigned int I, unsigned int M, unsigned int N, typename T>
56  public:
58  for (int i = 0; i < I; i++) {
59  uut.getIn(i).connect(data[i]);
60  }
61  }
62 
63  int run(const char* filepath) {
64  std::ifstream file(filepath);
65  if (!file.is_open()) return -2;
66 
67  int line = 0;
68  int error = 0;
69 
70  while (!file.eof()) {
71  line++;
72 
73  T testValue;
74  for (int i = 0; i < I; i++) {
75  for(unsigned int j = 0; j < M * N; j++) {
76  double in;
77  file >> in; // read input data
78  testValue(j) = in;
79  }
80  data[i].getSignal().setValue(testValue);
81  }
82  if (file.eof()) break;
83  T refRes;
84  for(unsigned int j = 0; j < M * N; j++) {
85  double out;
86  file >> out; // read reference data
87  refRes(j) = out;
88  }
89 
90  uut.run();
91 
92  for(unsigned int j = 0; j < M * N; j++) {
93  if(!Utils::compareApprox(refRes(j), uut.getOut().getSignal().getValue()(j), 0.001)) {
94  error++;
95  std::cout << "line " << line << " expecting " << refRes(j) << " calculated " << uut.getOut().getSignal().getValue()(j) << std::endl;
96  }
97  }
98  }
99 
100  file.close();
101  return error;
102  }
103 
104  protected:
107 };
108 
109 #endif // ORG_EEROS_TEST_CONTROL_SUMBLOCKTEST_HPP_
SumBlockTestMatrix()
Definition: SumBlockTest.hpp:57
eeros::control::Sum< I, T > uut
Definition: SumBlockTest.hpp:51
static bool compareApprox(double ref, double val, double tolerance)
Definition: Utils.hpp:7
Definition: SumBlockTest.hpp:55
SumBlockTestScalar()
Definition: SumBlockTest.hpp:14
virtual Output< T > & getOut()
Definition: Sum.hpp:36
Definition: SumBlockTest.hpp:12
std::ifstream file
Definition: MatrixOperations.cpp:29
void error(int line, eeros::RingBuffer< int, 4 > &rb)
Definition: RingBufferTest.cpp:24
Definition: Output.hpp:10
int run(const char *filepath)
Definition: SumBlockTest.hpp:63
eeros::control::Sum< I, T > uut
Definition: SumBlockTest.hpp:106
int j
Definition: RingBufferTest.cpp:13
void endl(LogWriter &w)
Definition: RecordWriter.hpp:19
eeros::control::Output< T > data[I]
Definition: SumBlockTest.hpp:50
int run(const char *filepath)
Definition: SumBlockTest.hpp:20
int i
Definition: RingBufferTest.cpp:12
virtual void run()
Definition: Sum.hpp:22
eeros::control::Output< T > data[I]
Definition: SumBlockTest.hpp:105
virtual Input< T > & getIn(uint8_t index)
Definition: Sum.hpp:32