Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by kifir on 6/18/24. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | #include "ac_test_base.h" | |||
8 | #include "engine_configuration_defaults.h" | |||
9 | ||||
10 | namespace { | |||
11 | constexpr uint16_t TEST_MIN_AC_PRESSURE = 17; | |||
12 | constexpr uint16_t TEST_MAX_AC_PRESSURE = 239; | |||
13 | constexpr float TEST_AC_PRESSURE_ENABLE_HYSTERESIS = 2.0f; | |||
14 | constexpr uint16_t DEADBAND_WIDTH = AcController::PRESSURE_DEADBAND_WIDTH; | |||
15 | ||||
16 | class AcPressureTestConfig : public AcTestConfig { | |||
17 | public: | |||
18 | AcPressureTestConfig( | |||
19 | std::optional<uint16_t> minAcPressure, | |||
20 | std::optional<uint16_t> maxAcPressure, | |||
21 | std::optional<float> acPressureEnableHysteresis | |||
22 | ); | |||
23 | }; | |||
24 | ||||
25 | 3 | AcPressureTestConfig::AcPressureTestConfig( | ||
26 | const std::optional<uint16_t> minAcPressure, | |||
27 | const std::optional<uint16_t> maxAcPressure, | |||
28 | const std::optional<float> acPressureEnableHysteresis | |||
29 | 3 | ) { | ||
30 | 3 | setMinAcPressure(minAcPressure); | ||
31 | 3 | setMaxAcPressure(maxAcPressure); | ||
32 | 3 | setAcPressureEnableHysteresis(acPressureEnableHysteresis); | ||
33 | 3 | } | ||
34 | ||||
35 | struct AcPressureTestData { | |||
36 | const std::string context; | |||
37 | const float acPressure; | |||
38 | const bool expectedAcPressureTooLow; | |||
39 | const bool expectedAcPressureTooHigh; | |||
40 | }; | |||
41 | ||||
42 | class AcPressureTest : public AcTestBase { | |||
43 | protected: | |||
44 | static const AcPressureTestConfig DEFAULT_AC_PRESSURE_CONFIG; | |||
45 | static const AcPressureTestConfig TEST_AC_PRESSURE_CONFIG; | |||
46 | ||||
47 | void doTest(const AcPressureTestConfig& config, const std::vector<AcPressureTestData>& testData); | |||
48 | private: | |||
49 | void checkPersistentIndicators(); | |||
50 | }; | |||
51 | ||||
52 | const AcPressureTestConfig AcPressureTest::DEFAULT_AC_PRESSURE_CONFIG = { {}, {}, {} }; | |||
53 | ||||
54 | const AcPressureTestConfig AcPressureTest::TEST_AC_PRESSURE_CONFIG = { | |||
55 | { TEST_MIN_AC_PRESSURE }, | |||
56 | { TEST_MAX_AC_PRESSURE }, | |||
57 | { TEST_AC_PRESSURE_ENABLE_HYSTERESIS } | |||
58 | }; | |||
59 | ||||
60 | 5 | void AcPressureTest::doTest(const AcPressureTestConfig& config, const std::vector<AcPressureTestData>& testData) { | ||
61 | 5 | setUpTestConfig(config); | ||
62 | ||||
63 | 5 | engineConfiguration->acDelay = 0; | ||
64 | 5 | Sensor::setMockValue(SensorType::Rpm, 500); // to avoid engineTooSlow | ||
65 | 5 | engine->engineState.lua.acRequestState = true; // to emulate pressed A/C button | ||
66 | ||||
67 |
2/2✓ Branch 7 taken 27 times.
✓ Branch 8 taken 5 times.
|
2/2✓ Decision 'true' taken 27 times.
✓ Decision 'false' taken 5 times.
|
32 | for (const AcPressureTestData& testDataItem: testData) { |
68 |
1/1✓ Branch 1 taken 27 times.
|
27 | updateAcPressure(testDataItem.acPressure); | |
69 | ||||
70 |
1/1✓ Branch 1 taken 27 times.
|
27 | checkPersistentIndicators(); | |
71 |
3/7✓ Branch 3 taken 27 times.
✓ Branch 7 taken 27 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27 times.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
27 | EXPECT_EQ( | |
72 | engine->engineModules.get<AcController>()->acPressureTooLow, | |||
73 | testDataItem.expectedAcPressureTooLow | |||
74 |
0/1✗ Branch 1 not taken.
|
27 | ) << testDataItem.context; | |
75 |
3/7✓ Branch 3 taken 27 times.
✓ Branch 7 taken 27 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27 times.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
27 | EXPECT_EQ( | |
76 | engine->engineModules.get<AcController>()->acPressureTooHigh, | |||
77 | testDataItem.expectedAcPressureTooHigh | |||
78 |
0/1✗ Branch 1 not taken.
|
27 | ) << testDataItem.context; | |
79 | 27 | const bool shouldAcBeEnabled = !testDataItem.expectedAcPressureTooLow | ||
80 |
4/4✓ Branch 0 taken 21 times.
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 6 times.
|
27 | && !testDataItem.expectedAcPressureTooHigh; | |
81 |
4/8✓ Branch 3 taken 27 times.
✓ Branch 7 taken 27 times.
✓ Branch 10 taken 27 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 27 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_EQ(engine->engineModules.get<AcController>()->isAcEnabled(), shouldAcBeEnabled) | |
82 |
0/1✗ Branch 1 not taken.
|
27 | << testDataItem.context; | |
83 |
3/7✓ Branch 3 taken 27 times.
✓ Branch 7 taken 27 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 27 times.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
27 | EXPECT_EQ(engine->engineModules.get<AcController>()->acCompressorState, shouldAcBeEnabled) | |
84 |
0/1✗ Branch 1 not taken.
|
27 | << testDataItem.context; | |
85 |
3/8✓ Branch 3 taken 27 times.
✓ Branch 6 taken 27 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 27 times.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_EQ(enginePins.acRelay.getLogicValue(), shouldAcBeEnabled) << testDataItem.context; | |
86 | } | |||
87 | 5 | } | ||
88 | ||||
89 | 27 | void AcPressureTest::checkPersistentIndicators() { | ||
90 |
2/7✓ Branch 2 taken 27 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 27 times.
✗ Branch 11 not taken.
✗ Branch 16 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
|
27 | EXPECT_TRUE(engine->engineModules.get<AcController>()->acButtonState); | |
91 |
2/7✓ Branch 3 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_FALSE(engine->engineModules.get<AcController>()->engineTooSlow); | |
92 |
2/7✓ Branch 3 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_FALSE(engine->engineModules.get<AcController>()->engineTooFast); | |
93 |
2/7✓ Branch 3 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_FALSE(engine->engineModules.get<AcController>()->noClt); | |
94 |
2/7✓ Branch 3 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_FALSE(engine->engineModules.get<AcController>()->engineTooHot); | |
95 |
2/7✓ Branch 3 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_FALSE(engine->engineModules.get<AcController>()->tpsTooHigh); | |
96 |
2/7✓ Branch 3 taken 27 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 27 times.
✗ Branch 13 not taken.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✗ Branch 25 not taken.
|
27 | EXPECT_FALSE(engine->engineModules.get<AcController>()->isDisabledByLua); | |
97 | 27 | } | ||
98 | ||||
99 | 4 | TEST_F(AcPressureTest, pressureTooLow) { | ||
100 |
4/6✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 1 time.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
10 | doTest( | |
101 | /* config = */ TEST_AC_PRESSURE_CONFIG, | |||
102 | /* testData = */ { | |||
103 | { | |||
104 | "acPressure = (TEST_MIN_AC_PRESSURE + TEST_MAX_AC_PRESSURE) / 2.0", | |||
105 | (TEST_MIN_AC_PRESSURE + TEST_MAX_AC_PRESSURE) / 2.0, | |||
106 | false, | |||
107 | false | |||
108 | }, | |||
109 | { | |||
110 | "acPressure = TEST_MIN_AC_PRESSURE - DEADBAND_WIDTH", | |||
111 | TEST_MIN_AC_PRESSURE - DEADBAND_WIDTH, | |||
112 | false, | |||
113 | false | |||
114 | }, | |||
115 | { | |||
116 | "acPressure = TEST_MIN_AC_PRESSURE - DEADBAND_WIDTH - EPS5D", | |||
117 | TEST_MIN_AC_PRESSURE - DEADBAND_WIDTH - EPS5D, | |||
118 | true, | |||
119 | false | |||
120 | }, | |||
121 | { | |||
122 | "acPressure = TEST_MIN_AC_PRESSURE", | |||
123 | TEST_MIN_AC_PRESSURE, | |||
124 | true, | |||
125 | false | |||
126 | }, | |||
127 | { | |||
128 | "acPressure = TEST_MIN_AC_PRESSURE + DEADBAND_WIDTH", | |||
129 | TEST_MIN_AC_PRESSURE + DEADBAND_WIDTH, | |||
130 | true, | |||
131 | false | |||
132 | }, | |||
133 | { | |||
134 | "acPressure = TEST_MIN_AC_PRESSURE + DEADBAND_WIDTH + EPS5D", | |||
135 | TEST_MIN_AC_PRESSURE + DEADBAND_WIDTH + EPS5D, | |||
136 | false, | |||
137 | false | |||
138 | } | |||
139 | } | |||
140 | ); | |||
141 | 4 | } | ||
142 | ||||
143 | 4 | TEST_F(AcPressureTest, pressureTooHigh) { | ||
144 |
4/6✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 1 time.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
9 | doTest( | |
145 | /* config = */ TEST_AC_PRESSURE_CONFIG, | |||
146 | /* testData = */ { | |||
147 | { | |||
148 | "acPressure = (TEST_MIN_AC_PRESSURE + TEST_MAX_AC_PRESSURE) / 2.0", | |||
149 | (TEST_MIN_AC_PRESSURE + TEST_MAX_AC_PRESSURE) / 2.0, | |||
150 | false, | |||
151 | false | |||
152 | }, | |||
153 | { | |||
154 | "acPressure = TEST_MAX_AC_PRESSURE", | |||
155 | TEST_MAX_AC_PRESSURE, | |||
156 | false, | |||
157 | false | |||
158 | }, | |||
159 | { | |||
160 | "acPressure = TEST_MAX_AC_PRESSURE + EPS5D", | |||
161 | TEST_MAX_AC_PRESSURE + EPS5D, | |||
162 | false, | |||
163 | true | |||
164 | }, | |||
165 | { | |||
166 | "acPressure = TEST_MAX_AC_PRESSURE - TEST_AC_PRESSURE_ENABLE_HYSTERESIS", | |||
167 | TEST_MAX_AC_PRESSURE - TEST_AC_PRESSURE_ENABLE_HYSTERESIS, | |||
168 | false, | |||
169 | true | |||
170 | }, | |||
171 | { | |||
172 | "acPressure = TEST_MAX_AC_PRESSURE - TEST_AC_PRESSURE_ENABLE_HYSTERESIS - EPS5D", | |||
173 | TEST_MAX_AC_PRESSURE - TEST_AC_PRESSURE_ENABLE_HYSTERESIS - EPS5D, | |||
174 | false, | |||
175 | false | |||
176 | } | |||
177 | } | |||
178 | ); | |||
179 | 4 | } | ||
180 | ||||
181 | ||||
182 | 4 | TEST_F(AcPressureTest, pressureTooHighWithZeroHysteresis) { | ||
183 |
4/6✓ Branch 3 taken 1 time.
✓ Branch 14 taken 1 time.
✓ Branch 22 taken 5 times.
✓ Branch 23 taken 1 time.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
|
11 | doTest( | |
184 | 2 | /* config = */ { {}, {}, { 0.0f } }, | ||
185 | /* testData = */ { | |||
186 | { | |||
187 | "acPressure = (engine_configuration_defaults::MIN_AC_PRESSURE + engine_configuration_defaults::MAX_AC_PRESSURE) / 2.0", | |||
188 | (engine_configuration_defaults::MIN_AC_PRESSURE + engine_configuration_defaults::MAX_AC_PRESSURE) / 2.0, | |||
189 | false, | |||
190 | false | |||
191 | }, | |||
192 | { | |||
193 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE", | |||
194 | engine_configuration_defaults::MAX_AC_PRESSURE, | |||
195 | false, | |||
196 | false | |||
197 | }, | |||
198 | { | |||
199 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE + EPS4D", | |||
200 | engine_configuration_defaults::MAX_AC_PRESSURE + EPS4D, | |||
201 | false, | |||
202 | true | |||
203 | }, | |||
204 | { | |||
205 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE", | |||
206 | engine_configuration_defaults::MAX_AC_PRESSURE, | |||
207 | false, | |||
208 | true | |||
209 | }, | |||
210 | { | |||
211 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE - EPS4D", | |||
212 | engine_configuration_defaults::MAX_AC_PRESSURE - EPS4D, | |||
213 | false, | |||
214 | false | |||
215 | } | |||
216 | } | |||
217 | ); | |||
218 | 4 | } | ||
219 | ||||
220 | 4 | TEST_F(AcPressureTest, defaultMinAcPressure) { | ||
221 |
4/6✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 6 times.
✓ Branch 11 taken 1 time.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
10 | doTest( | |
222 | /* config = */ DEFAULT_AC_PRESSURE_CONFIG, | |||
223 | /* testData = */ { | |||
224 | { | |||
225 | "acPressure = (DEFAULT_MIN_AC_PRESSURE + DEFAULT_MAX_AC_PRESSURE) / 2.0", | |||
226 | (engine_configuration_defaults::MIN_AC_PRESSURE + engine_configuration_defaults::MAX_AC_PRESSURE) / 2.0, | |||
227 | false, | |||
228 | false | |||
229 | }, | |||
230 | { | |||
231 | "acPressure = engine_configuration_defaults::MIN_AC_PRESSURE - DEADBAND_WIDTH", | |||
232 | engine_configuration_defaults::MIN_AC_PRESSURE - DEADBAND_WIDTH, | |||
233 | false, | |||
234 | false | |||
235 | }, | |||
236 | { | |||
237 | "acPressure = engine_configuration_defaults::MIN_AC_PRESSURE - DEADBAND_WIDTH - EPS5D", | |||
238 | engine_configuration_defaults::MIN_AC_PRESSURE - DEADBAND_WIDTH - EPS5D, | |||
239 | true, | |||
240 | false | |||
241 | }, | |||
242 | { | |||
243 | "acPressure = engine_configuration_defaults::MIN_AC_PRESSURE", | |||
244 | engine_configuration_defaults::MIN_AC_PRESSURE, | |||
245 | true, | |||
246 | false | |||
247 | }, | |||
248 | { | |||
249 | "acPressure = engine_configuration_defaults::MIN_AC_PRESSURE + DEADBAND_WIDTH", | |||
250 | engine_configuration_defaults::MIN_AC_PRESSURE + DEADBAND_WIDTH, | |||
251 | true, | |||
252 | false | |||
253 | }, | |||
254 | { | |||
255 | "acPressure = engine_configuration_defaults::MIN_AC_PRESSURE + DEADBAND_WIDTH + EPS5D", | |||
256 | engine_configuration_defaults::MIN_AC_PRESSURE + DEADBAND_WIDTH + EPS5D, | |||
257 | false, | |||
258 | false | |||
259 | } | |||
260 | } | |||
261 | ); | |||
262 | 4 | } | ||
263 | ||||
264 | 4 | TEST_F(AcPressureTest, defaultMaxAcPressure) { | ||
265 |
4/6✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 5 times.
✓ Branch 11 taken 1 time.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
9 | doTest( | |
266 | /* config = */ DEFAULT_AC_PRESSURE_CONFIG, | |||
267 | /* testData = */ { | |||
268 | { | |||
269 | "acPressure = (engine_configuration_defaults::MIN_AC_PRESSURE + engine_configuration_defaults::MAX_AC_PRESSURE) / 2.0", | |||
270 | (engine_configuration_defaults::MIN_AC_PRESSURE + engine_configuration_defaults::MAX_AC_PRESSURE) / 2.0, | |||
271 | false, | |||
272 | false | |||
273 | }, | |||
274 | { | |||
275 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE", | |||
276 | engine_configuration_defaults::MAX_AC_PRESSURE, | |||
277 | false, | |||
278 | false | |||
279 | }, | |||
280 | { | |||
281 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE + EPS4D", | |||
282 | engine_configuration_defaults::MAX_AC_PRESSURE + EPS4D, | |||
283 | false, | |||
284 | true | |||
285 | }, | |||
286 | { | |||
287 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE - engine_configuration_defaults::AC_PRESSURE_ENABLE_HYST", | |||
288 | engine_configuration_defaults::MAX_AC_PRESSURE - engine_configuration_defaults::AC_PRESSURE_ENABLE_HYST, | |||
289 | false, | |||
290 | true | |||
291 | }, | |||
292 | { | |||
293 | "acPressure = engine_configuration_defaults::MAX_AC_PRESSURE - engine_configuration_defaults::AC_PRESSURE_ENABLE_HYST - EPS4D", | |||
294 | engine_configuration_defaults::MAX_AC_PRESSURE - engine_configuration_defaults::AC_PRESSURE_ENABLE_HYST - EPS4D, | |||
295 | false, | |||
296 | false | |||
297 | } | |||
298 | } | |||
299 | ); | |||
300 | 4 | } | ||
301 | } | |||
302 |