forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgood-assert.cpp
57 lines (44 loc) · 1.19 KB
/
good-assert.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <ArduinoUnitTests.h>
#include "../do-something.h"
class NonOrderedType {
public:
int x; // ehh why not
NonOrderedType(int some_x) : x(some_x) {}
bool operator==(const NonOrderedType &that) const {
return that.x == x;
}
bool operator!=(const NonOrderedType &that) const {
return that.x != x;
}
};
inline std::ostream& operator << ( std::ostream& out, const NonOrderedType& n ) {
out << "NonOrderedType(" << n.x << ")";
return out;
}
unittest(assert_equal_without_total_ordering)
{
NonOrderedType a(3);
NonOrderedType b(3);
NonOrderedType c(4);
assertEqual(a, b);
assertEqual(a, a);
assertNotEqual(a, c);
}
unittest(float_assertions)
{
assertEqualFloat(1.0, 1.02, 0.1);
assertNotEqualFloat(1.2, 1.0, 0.01);
assertInfinity(exp(800));
assertInfinity(1.0/0.0);
assertNotInfinity(42);
assertNAN(INFINITY - INFINITY);
assertNAN(0.0/0.0);
assertNotNAN(42);
assertComparativeEquivalent(exp(800), INFINITY);
assertComparativeEquivalent(0.0/0.0, INFINITY - INFINITY);
assertComparativeNotEquivalent(INFINITY, -INFINITY);
assertLess(0, INFINITY);
assertLess(-INFINITY, 0);
assertLess(-INFINITY, INFINITY);
}
unittest_main()