Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | * @file vvl_controller_afr_condition.cpp | |||
3 | * | |||
4 | * @date: ago 27, 2025 | |||
5 | * @author FDSoftware, kifir | |||
6 | */ | |||
7 | ||||
8 | #include "pch.h" | |||
9 | ||||
10 | #include "engine_configuration_defaults.h" | |||
11 | ||||
12 | #include "util/test_base.h" | |||
13 | ||||
14 | namespace { | |||
15 | static constexpr float TEST_DEFAULT_LAMBDA1 = engine_configuration_defaults::NITROUS_MAXIMUM_AFR / STOICH_RATIO; | |||
16 | ||||
17 | static constexpr float TEST_MAXIMUM_AFR = 12.3; | |||
18 | static constexpr float TEST_LAMBDA1 = TEST_MAXIMUM_AFR / STOICH_RATIO; | |||
19 | ||||
20 | struct AfrConditionTestData { | |||
21 | const std::optional<float> lambda1; | |||
22 | const bool expectedAfrCondition; | |||
23 | const char* const context; | |||
24 | }; | |||
25 | ||||
26 | 3 | void checkAfrCondition(const std::vector<AfrConditionTestData>& testData) { | ||
27 |
2/2✓ Branch 7 taken 13 times.
✓ Branch 8 taken 3 times.
|
2/2✓ Decision 'true' taken 13 times.
✓ Decision 'false' taken 3 times.
|
16 | for (const AfrConditionTestData& item: testData) { |
28 |
1/1✓ Branch 3 taken 13 times.
|
13 | Sensor::setMockValue(SensorType::Lambda1, item.lambda1.value_or(0.0f)); | |
29 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 5 taken 13 times.
|
13 | engine->module<VvlController>().unmock().onSlowCallback(); | |
30 | ||||
31 |
3/7✓ Branch 3 taken 13 times.
✓ Branch 7 taken 13 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 13 times.
✗ Branch 15 not taken.
✗ Branch 19 not taken.
✗ Branch 22 not taken.
|
13 | EXPECT_EQ(engine->module<VvlController>().unmock().isVvlAfrCondition, item.expectedAfrCondition) | |
32 |
0/1✗ Branch 1 not taken.
|
13 | << item.context; | |
33 | } | |||
34 | 3 | } | ||
35 | ||||
36 | 4 | TEST(VvlAfrConditionTest, checkDefaultWithDisabledVvlControl) { | ||
37 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
38 | 1 | engineConfiguration->vvlControlEnabled = false; | ||
39 | ||||
40 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkAfrCondition({ | |
41 | { {}, false, "default" }, | |||
42 | { { 0.0f }, false, "0.0" }, | |||
43 | { { TEST_LAMBDA1 - EPS5D }, false, "TEST_LAMBDA1 - EPS5D" }, | |||
44 | { { TEST_LAMBDA1 }, false, "TEST_LAMBDA1" }, | |||
45 | { { TEST_LAMBDA1 + EPS5D }, false, "TEST_LAMBDA1 + EPS5D" }, | |||
46 | }); | |||
47 | 2 | } | ||
48 | ||||
49 | 4 | TEST(VvlAfrConditionTest, checkZeroMaximumAfr) { | ||
50 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
51 | 1 | engineConfiguration->vvlControlEnabled = true; | ||
52 | ||||
53 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkAfrCondition({ | |
54 | { { 0.0f }, true, "0.0" }, | |||
55 | { { TEST_LAMBDA1 - EPS5D }, true, "TEST_LAMBDA1 - EPS5D" }, | |||
56 | { { TEST_LAMBDA1 }, true, "TEST_LAMBDA1" }, | |||
57 | { { TEST_LAMBDA1 + EPS5D }, true, "TEST_LAMBDA1 + EPS5D" }, | |||
58 | }); | |||
59 | 2 | } | ||
60 | ||||
61 | 4 | TEST(VvlAfrConditionTest, checkMaximumAfr) { | ||
62 |
1/1✓ Branch 2 taken 1 time.
|
1 | EngineTestHelper eth(engine_type_e::TEST_ENGINE); | |
63 | 1 | engineConfiguration->vvlControlEnabled = true; | ||
64 | 1 | engineConfiguration->vvlController.maximumAfr = TEST_MAXIMUM_AFR; | ||
65 | ||||
66 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkAfrCondition({ | |
67 | { { 0.0f }, true, "0.0" }, | |||
68 | { { TEST_LAMBDA1 - EPS5D }, true, "TEST_LAMBDA1 - EPS5D" }, | |||
69 | { { TEST_LAMBDA1 }, true, "TEST_LAMBDA1" }, | |||
70 | { { TEST_LAMBDA1 + EPS5D }, false, "TEST_LAMBDA1 + EPS5D" }, | |||
71 | }); | |||
72 | 2 | } | ||
73 | } | |||
74 |