Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by kifir on 12/1/24. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | #include "engine_configuration_defaults.h" | |||
8 | ||||
9 | #include "util/test_base.h" | |||
10 | ||||
11 | namespace { | |||
12 | struct RpmConditionTestData { | |||
13 | const std::optional<float> rpm; | |||
14 | const bool expectedRpmCondition; | |||
15 | const char* const context; | |||
16 | }; | |||
17 | ||||
18 | class NitrousRpmConditionTest : public TestBase<> { | |||
19 | protected: | |||
20 | static constexpr uint16_t TEST_ACTIVATION_RPM = 239; | |||
21 | static constexpr uint16_t TEST_DEACTIVATION_RPM = 932; | |||
22 | static constexpr uint16_t TEST_DEACTIVATION_RPM_WINDOW = 17; | |||
23 | static constexpr uint16_t TEST_DEACTIVATION_RPM_WINDOW_BEGIN | |||
24 | = TEST_DEACTIVATION_RPM - TEST_DEACTIVATION_RPM_WINDOW; | |||
25 | ||||
26 | static constexpr float BEFORE_TEST_ACTIVATION_RPM = TEST_ACTIVATION_RPM - EPS5D; | |||
27 | static constexpr float BEFORE_TEST_DEACTIVATION_RPM_WINDOW_BEGIN = TEST_DEACTIVATION_RPM_WINDOW_BEGIN - EPS4D; | |||
28 | static constexpr float BEFORE_TEST_DEACTIVATION_RPM = TEST_DEACTIVATION_RPM - EPS4D; | |||
29 | ||||
30 | static constexpr uint16_t DEFAULT_ACTIVATION_RPM = engine_configuration_defaults::NITROUS_ACTIVATION_RPM; | |||
31 | static constexpr uint16_t DEFAULT_DEACTIVATION_RPM = engine_configuration_defaults::NITROUS_DEACTIVATION_RPM; | |||
32 | static constexpr uint16_t DEFAULT_DEACTIVATION_RPM_WINDOW = | |||
33 | engine_configuration_defaults::NITROUS_DEACTIVATION_RPM_WINDOW; | |||
34 | static constexpr uint16_t DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN = | |||
35 | DEFAULT_DEACTIVATION_RPM - DEFAULT_DEACTIVATION_RPM_WINDOW; | |||
36 | ||||
37 | static constexpr float BEFORE_DEFAULT_ACTIVATION_RPM = DEFAULT_ACTIVATION_RPM - EPS3D; | |||
38 | static constexpr float BEFORE_DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN = | |||
39 | DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN - EPS3D; | |||
40 | static constexpr float BEFORE_DEFAULT_DEACTIVATION_RPM = DEFAULT_DEACTIVATION_RPM - EPS3D; | |||
41 | ||||
42 | void checkRpmCondition(const std::vector<RpmConditionTestData>& testData); | |||
43 | void checkRpmConditionIsAlwaysUnsatisfied(); | |||
44 | }; | |||
45 | ||||
46 | 4 | void NitrousRpmConditionTest::checkRpmCondition(const std::vector<RpmConditionTestData>& testData) { | ||
47 |
2/2✓ Branch 7 taken 46 times.
✓ Branch 8 taken 4 times.
|
2/2✓ Decision 'true' taken 46 times.
✓ Decision 'false' taken 4 times.
|
50 | for (const RpmConditionTestData& item: testData) { |
48 |
1/1✓ Branch 1 taken 46 times.
|
46 | updateRpm(item.rpm, &TestBase::periodicSlowCallback); | |
49 |
3/7✓ Branch 3 taken 46 times.
✓ Branch 6 taken 46 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 46 times.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
|
46 | EXPECT_EQ(getModule<NitrousController>().isNitrousRpmCondition, item.expectedRpmCondition) | |
50 |
0/1✗ Branch 1 not taken.
|
46 | << item.context; | |
51 | } | |||
52 | 4 | } | ||
53 | ||||
54 | 2 | void NitrousRpmConditionTest::checkRpmConditionIsAlwaysUnsatisfied() { | ||
55 |
2/2✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
6 | checkRpmCondition({ | |
56 | { {0}, false, "rpm = 0" }, | |||
57 | { { BEFORE_TEST_ACTIVATION_RPM }, false, "rpm = BEFORE_TEST_ACTIVATION_RPM" }, | |||
58 | { { TEST_ACTIVATION_RPM }, false, "rpm = TEST_ACTIVATION_RPM" }, | |||
59 | { { BEFORE_TEST_ACTIVATION_RPM }, false, "rpm = BEFORE_TEST_ACTIVATION_RPM" }, | |||
60 | { { TEST_DEACTIVATION_RPM }, false, "rpm = TEST_DEACTIVATION_RPM" }, | |||
61 | { { TEST_DEACTIVATION_RPM + 1 }, false, "rpm = TEST_DEACTIVATION_RPM + 1" }, | |||
62 | { { DEFAULT_ACTIVATION_RPM }, false, "rpm = DEFAULT_ACTIVATION_RPM" }, | |||
63 | { { DEFAULT_DEACTIVATION_RPM }, false, "rpm = DEFAULT_DEACTIVATION_RPM" }, | |||
64 | { { TEST_DEACTIVATION_RPM_WINDOW_BEGIN }, false, "rpm = TEST_DEACTIVATION_RPM_WINDOW_BEGIN" }, | |||
65 | { { BEFORE_TEST_DEACTIVATION_RPM_WINDOW_BEGIN }, false, "rpm = BEFORE_TEST_DEACTIVATION_RPM_WINDOW_BEGIN" }, | |||
66 | { { TEST_DEACTIVATION_RPM_WINDOW_BEGIN }, false, "rpm = TEST_DEACTIVATION_RPM_WINDOW_BEGIN (again)" }, | |||
67 | { { BEFORE_TEST_DEACTIVATION_RPM }, false, "rpm = BEFORE_TEST_DEACTIVATION_RPM (again)" }, | |||
68 | { { TEST_DEACTIVATION_RPM }, false, "rpm = TEST_DEACTIVATION_RPM (again)" }, | |||
69 | }); | |||
70 | 2 | } | ||
71 | ||||
72 | 4 | TEST_F(NitrousRpmConditionTest, checkDefault) { | ||
73 | 1 | checkRpmConditionIsAlwaysUnsatisfied(); | ||
74 | 1 | } | ||
75 | ||||
76 | 4 | TEST_F(NitrousRpmConditionTest, checkDefaultWithDisabledNitrousControl) { | ||
77 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ false })); | |
78 | 1 | checkRpmConditionIsAlwaysUnsatisfied(); | ||
79 | 1 | } | ||
80 | ||||
81 | 4 | TEST_F(NitrousRpmConditionTest, checkDefaultWithEnabledNitrousControl) { | ||
82 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ true })); | |
83 | ||||
84 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkRpmCondition({ | |
85 | { { 0 }, false, "rpm = 0" }, | |||
86 | { { BEFORE_DEFAULT_ACTIVATION_RPM }, false, "rpm = BEFORE_DEFAULT_ACTIVATION_RPM" }, | |||
87 | { { DEFAULT_ACTIVATION_RPM }, true, "rpm = DEFAULT_ACTIVATION_RPM" }, | |||
88 | { { BEFORE_DEFAULT_DEACTIVATION_RPM }, true, "rpm = BEFORE_DEFAULT_DEACTIVATION_RPM" }, | |||
89 | { { DEFAULT_DEACTIVATION_RPM }, false, "rpm = DEFAULT_DEACTIVATION_RPM" }, | |||
90 | { | |||
91 | { DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN }, | |||
92 | false, | |||
93 | "rpm = DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN (still in window)" | |||
94 | }, | |||
95 | { | |||
96 | { BEFORE_DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN }, | |||
97 | true, | |||
98 | "rpm = BEFORE_DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN" | |||
99 | }, | |||
100 | { | |||
101 | { DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN }, | |||
102 | true, | |||
103 | "rpm = DEFAULT_DEACTIVATION_RPM_WINDOW_BEGIN (returning to the window)" | |||
104 | }, | |||
105 | { { BEFORE_DEFAULT_DEACTIVATION_RPM }, true, "rpm = BEFORE_DEFAULT_DEACTIVATION_RPM (again)" }, | |||
106 | { { DEFAULT_DEACTIVATION_RPM }, false, "rpm = NITROUS_DEACTIVATION_RPM (again)" }, | |||
107 | }); | |||
108 | 1 | } | ||
109 | ||||
110 | 4 | TEST_F(NitrousRpmConditionTest, checkActivationAndDeactivation) { | ||
111 |
1/1✓ Branch 2 taken 1 time.
|
2 | setUpEngineConfiguration( | |
112 | 1 | EngineConfig() | ||
113 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setNitrousControlEnabled({ true }) | |
114 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setNitrousActivationRpm({ TEST_ACTIVATION_RPM }) | |
115 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setNitrousDeactivationRpm({ TEST_DEACTIVATION_RPM }) | |
116 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setNitrousDeactivationRpmWindow({ TEST_DEACTIVATION_RPM_WINDOW }) | |
117 | ); | |||
118 | ||||
119 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkRpmCondition({ | |
120 | { { 0 }, false, "rpm = 0" }, | |||
121 | { { BEFORE_TEST_ACTIVATION_RPM }, false, "rpm = BEFORE_TEST_ACTIVATION_RPM" }, | |||
122 | { { TEST_ACTIVATION_RPM }, true, "rpm = TEST_ACTIVATION_RPM" }, | |||
123 | { { BEFORE_TEST_DEACTIVATION_RPM }, true, "rpm = BEFORE_TEST_DEACTIVATION_RPM" }, | |||
124 | { { TEST_DEACTIVATION_RPM }, false, "rpm = TEST_DEACTIVATION_RPM" }, | |||
125 | { | |||
126 | { TEST_DEACTIVATION_RPM_WINDOW_BEGIN }, | |||
127 | false, | |||
128 | "rpm = TEST_DEACTIVATION_RPM_WINDOW_BEGIN (still in window)" | |||
129 | }, | |||
130 | { { BEFORE_TEST_DEACTIVATION_RPM_WINDOW_BEGIN }, true, "rpm = BEFORE_TEST_DEACTIVATION_RPM_WINDOW_BEGIN" }, | |||
131 | { | |||
132 | { TEST_DEACTIVATION_RPM_WINDOW_BEGIN }, | |||
133 | true, | |||
134 | "rpm = TEST_DEACTIVATION_RPM_WINDOW_BEGIN (returning to the window)" | |||
135 | }, | |||
136 | { { BEFORE_TEST_DEACTIVATION_RPM }, true, "rpm = BEFORE_TEST_DEACTIVATION_RPM (again)" }, | |||
137 | { { TEST_DEACTIVATION_RPM }, false, "rpm = TEST_DEACTIVATION_RPM (again)" }, | |||
138 | }); | |||
139 | 1 | } | ||
140 | } | |||
141 |