-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.h
44 lines (39 loc) · 1.13 KB
/
unit_test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// unit testing
void unit_test();
#define UT_BEGIN() int UT_tests = 0; int UT_fails = 0;
#define UT_END() Serial.print("UNIT TESTS: "); \
if (UT_fails > 0) { \
Serial.print("FAILED, "); \
} else { \
Serial.print("PASSED, "); \
} \
Serial.print(UT_fails); \
Serial.print(" / "); \
Serial.println(UT_tests); \
//return UT_fails;
// UT_EXPECT is used with integer values. It requires values to be exactly the same.
#define UT_EXPECT(expected, actual) \
UT_tests++; \
if ((expected) != (actual)) \
{ \
UT_fails++; \
Serial.print("ERROR: expected="); \
Serial.print(expected); \
Serial.print(", actual="); \
Serial.print(actual); \
Serial.print(": line "); \
Serial.println(__LINE__); \
}
// UT_EXPECT_FLOAT is used with floats. It will accept small difference in float values (it just happens sometimes with floats).
#define UT_EXPECT_FLOAT(expected, actual) \
UT_tests++; \
if (abs((expected) - (actual)) > 0.0001) \
{ \
UT_fails++; \
Serial.print("ERROR: expected="); \
Serial.print(expected); \
Serial.print(", actual="); \
Serial.print(actual); \
Serial.print(": line "); \
Serial.println(__LINE__); \
}