2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
18
19
20
21
22
23
25#ifndef CLOCKWERK_TEST_TOOLS_HPP
26#define CLOCKWERK_TEST_TOOLS_HPP
30#include "core/Matrix.hpp"
39 template<
typename T,
unsigned int R,
unsigned int C>
40 bool matrixCompare(
Matrix<T, R, C> expected,
Matrix<T, R, C> actual,
bool print=
false) {
41 bool test_pass =
true;
44 std::pair<
unsigned int,
unsigned int> exp_size = expected.size();
45 std::pair<
unsigned int,
unsigned int> act_size = actual.size();
46 if(exp_size.first != act_size.first || exp_size.second != act_size.second) {
53 for(
unsigned int i = 0; i < exp_size.first; i++) {
54 for(
unsigned int j = 0; j < exp_size.second; j++) {
55 expected.get(i, j, expected_val);
56 actual.get(i, j, actual_val);
57 if(expected_val != actual_val) {
60 if(std::isnan(actual_val)) {
67 if(print || !test_pass) {
68 std::cout<<
"Expected:"<<std::endl;
70 std::cout<<
"Actual: "<<std::endl;
82 template<
typename T,
unsigned int R,
unsigned int C>
83 bool matrixCompareTol(
Matrix<T, R, C> expected,
Matrix<T, R, C> actual,
const double &tolerance,
bool print=
false) {
84 bool test_pass =
true;
87 std::pair<
unsigned int,
unsigned int> exp_size = expected.size();
88 std::pair<
unsigned int,
unsigned int> act_size = actual.size();
89 if(exp_size.first != act_size.first || exp_size.second != act_size.second) {
96 for(
unsigned int i = 0; i < exp_size.first; i++) {
97 for(
unsigned int j = 0; j < exp_size.second; j++) {
98 expected.get(i, j, expected_val);
99 actual.get(i, j, actual_val);
100 if(std::abs(expected_val - actual_val) > tolerance) {
103 if(std::isnan(actual_val)) {
110 if(print || !test_pass) {
111 std::cout<<
"Expected:"<<std::endl;
113 std::cout<<
"Actual: "<<std::endl;
124 template<
typename T,
unsigned long int N>
125 bool arrayCompareTol(std::array<T, N> expected, std::array<T, N> actual,
const double &tolerance,
bool print=
false) {
126 bool test_pass =
true;
129 for(
unsigned int i = 0; i < N; i++) {
130 if(std::abs(expected[i] - actual[i]) > tolerance) {
133 if(std::isnan(actual[i])) {
139 if(print || !test_pass) {
140 std::cout<<
"Expected: [";
141 for(
unsigned int i = 0; i < N; i++) {
142 std::cout<<expected[i];
147 std::cout<<
"]\nActual: [";
148 for(
unsigned int i = 0; i < N; i++) {
149 std::cout<<actual[i];
154 std::cout<<
"]"<<std::endl;
Matrix math implementation.
Definition Matrix.hpp:54