Haptic Controller
Loading...
Searching...
No Matches
tests.hpp
Go to the documentation of this file.
1#include <Arduino.h>
2#include "defines.h"
3#include "utils/matrix.hpp"
4
5#define ASSERT_TRUE(X) \
6 Serial.print(#X); \
7 if (X) { \
8 Serial.println(" PASSED"); \
9 } else { \
10 Serial.println(" FAILED"); \
11 }
12
13#define LOADING(X) \
14 for (int i = 0; i < X; i++) { \
15 Serial.print("."); \
16 delay(1000); \
17 } \
18 Serial.println("");
19
21{
22 // Define some values to test against
23 auto test_matrix = Matrix(3, 3, {1, 2, 3, 4, 5, 6, 7, 8, 9});
24 const auto test_matrix_transpose = Matrix(3, 3, {1, 4, 7, 2, 5, 8, 3, 6, 9});
25 const auto test_vector = std::vector<float>{1, 2, 3};
26 const auto test_vector_product = std::vector<float>{14, 32, 50};
27
28 // Test matrix transposition
29 ASSERT_TRUE(test_matrix.T() == test_matrix_transpose)
30
31 // Test matrix multiplication
32 ASSERT_TRUE(test_matrix * test_vector == test_vector_product)
33}
34
37{
38 while (!Serial) {
39 Serial.println("Waiting for Serial connection...");
40 delay(10);
41 }
42
43 Serial.println("Running unit tests...");
45
46 Serial.println("Finished tests. Undefine #TESTING in defines.h for normal execution.");
47 while (true) {
48 delay(1000);
49 }
50}
Class that treats a std::vector as a matrix and implements simple operations.
Definition matrix.hpp:8
void matrixTests()
Definition tests.hpp:20
void allUnitTests()
Call in setup() in main.cpp to run unit tests instead of normal operation.
Definition tests.hpp:36