forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_deadband.cpp
55 lines (41 loc) · 1.17 KB
/
test_deadband.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
#include "pch.h"
#include "deadband.h"
TEST(Deadband, OutsideDeadband) {
Deadband<5> d;
EXPECT_TRUE(d.gt(100, 0));
EXPECT_FALSE(d.gt(0, 100));
}
TEST(Deadband, InsideDeadband) {
Deadband<5> d;
// stick the state to true
EXPECT_TRUE(d.gt(10, 0));
// Make sure it stays there while inside the deadband
EXPECT_TRUE(d.gt(0, 0));
EXPECT_TRUE(d.gt(0, 1));
EXPECT_TRUE(d.gt(0, 2));
EXPECT_TRUE(d.gt(0, 3));
EXPECT_TRUE(d.gt(0, 4));
EXPECT_TRUE(d.gt(0, 4.99));
// Flip the state - it should now stick false
EXPECT_FALSE(d.gt(0, 5.01));
// Make sure it stays there while inside the deadband
EXPECT_FALSE(d.gt(0, 4.99));
EXPECT_FALSE(d.gt(0, 1));
EXPECT_FALSE(d.gt(0, -1));
EXPECT_FALSE(d.gt(0, -1));
EXPECT_FALSE(d.gt(0, -4.99));
// Now it should flip back
EXPECT_TRUE(d.gt(0, -5.01));
}
TEST(Hysteresis, basic) {
Hysteresis h;
// Below 'rising', should stay false
EXPECT_FALSE(h.test(15, 30, 20));
EXPECT_FALSE(h.test(25, 30, 20));
// over 'rising', should go true
EXPECT_TRUE(h.test(31, 30, 20));
// drop back below 'rising', should stay true
EXPECT_TRUE(h.test(25, 30, 20));
// drop below 'falling', should go false
EXPECT_FALSE(h.test(15, 30, 20));
}