GCC Code Coverage Report


Directory: ./
File: unit_tests/tests/nitrous_control/test_nitrous_afr_condition.cpp
Date: 2025-10-03 00:57:22
Coverage Exec Excl Total
Lines: 100.0% 41 0 41
Functions: 100.0% 16 0 16
Branches: 83.9% 26 0 31
Decisions: 100.0% 2 - 2

Line Branch Decision Exec Source
1 //
2 // Created by kifir on 11/28/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 AfrConditionTestData {
13 const std::optional<float> lambda1;
14 const bool expectedAfrCondition;
15 const char* const context;
16 };
17
18 class NitrousAfrConditionTest : public TestBase<> {
19 protected:
20 static constexpr float TEST_DEFAULT_LAMBDA1 = engine_configuration_defaults::NITROUS_MAXIMUM_AFR / STOICH_RATIO;
21
22 static constexpr float TEST_MAXIMUM_AFR = 12.3;
23 static constexpr float TEST_LAMBDA1 = TEST_MAXIMUM_AFR / STOICH_RATIO;
24
25 void checkAfrCondition(const std::vector<AfrConditionTestData>& testData);
26 };
27
28 5 void NitrousAfrConditionTest::checkAfrCondition(const std::vector<AfrConditionTestData>& testData) {
29
2/2
✓ Branch 7 taken 25 times.
✓ Branch 8 taken 5 times.
2/2
✓ Decision 'true' taken 25 times.
✓ Decision 'false' taken 5 times.
30 for (const AfrConditionTestData& item: testData) {
30
1/1
✓ Branch 1 taken 25 times.
25 updateLambda1(item.lambda1, &TestBase::periodicSlowCallback);
31
3/7
✓ Branch 3 taken 25 times.
✓ Branch 6 taken 25 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 25 times.
✗ Branch 14 not taken.
✗ Branch 18 not taken.
✗ Branch 21 not taken.
25 EXPECT_EQ(getModule<NitrousController>().isNitrousAfrCondition, item.expectedAfrCondition)
32
0/1
✗ Branch 1 not taken.
25 << item.context;
33 }
34 5 }
35
36 4 TEST_F(NitrousAfrConditionTest, checkDefault) {
37
2/2
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
3 checkAfrCondition({
38 { {}, false, "default" },
39 { { 0.0f }, false, "0.0" },
40 { { TEST_LAMBDA1 - EPS5D }, false, "TEST_LAMBDA1 - EPS5D" },
41 { { TEST_LAMBDA1 }, false, "TEST_LAMBDA1" },
42 { { TEST_LAMBDA1 + EPS5D }, false, "TEST_LAMBDA1 + EPS5D" },
43 });
44 1 }
45
46 4 TEST_F(NitrousAfrConditionTest, checkDefaultWithDisabledNitrousControl) {
47
2/2
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ false }));
48
2/2
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
3 checkAfrCondition({
49 { {}, false, "default" },
50 { { 0.0f }, false, "0.0" },
51 { { TEST_LAMBDA1 - EPS5D }, false, "TEST_LAMBDA1 - EPS5D" },
52 { { TEST_LAMBDA1 }, false, "TEST_LAMBDA1" },
53 { { TEST_LAMBDA1 + EPS5D }, false, "TEST_LAMBDA1 + EPS5D" },
54 });
55 1 }
56
57 4 TEST_F(NitrousAfrConditionTest, checkDefaultWithEnabledNitrousControl) {
58
2/2
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ true }));
59
2/2
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
3 checkAfrCondition({
60 { {}, false, "default" },
61 { { 0.0f }, true, "0.0" },
62 { { TEST_DEFAULT_LAMBDA1 - EPS5D }, true, "TEST_DEFAULT_LAMBDA1 - EPS5D" },
63 { { TEST_DEFAULT_LAMBDA1 }, true, "TEST_DEFAULT_LAMBDA1" },
64 { { TEST_DEFAULT_LAMBDA1 + EPS5D }, false, "TEST_DEFAULT_LAMBDA1 + EPS5D" },
65 });
66 1 }
67
68 4 TEST_F(NitrousAfrConditionTest, checkZeroMaximumAfr) {
69
1/1
✓ Branch 2 taken 1 time.
2 setUpEngineConfiguration(
70 1 EngineConfig()
71
1/1
✓ Branch 6 taken 1 time.
3 .setNitrousControlEnabled({ true })
72
1/1
✓ Branch 5 taken 1 time.
4 .setNitrousMaximumAfr(0.0f)
73 );
74
2/2
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
3 checkAfrCondition({
75 { {}, true, "default" },
76 { { 0.0f }, true, "0.0" },
77 { { TEST_LAMBDA1 - EPS5D }, true, "TEST_LAMBDA1 - EPS5D" },
78 { { TEST_LAMBDA1 }, true, "TEST_LAMBDA1" },
79 { { TEST_LAMBDA1 + EPS5D }, true, "TEST_LAMBDA1 + EPS5D" },
80 });
81 1 }
82
83 4 TEST_F(NitrousAfrConditionTest, checkMaximumAfr) {
84
1/1
✓ Branch 2 taken 1 time.
2 setUpEngineConfiguration(
85 1 EngineConfig()
86
1/1
✓ Branch 6 taken 1 time.
3 .setNitrousControlEnabled({ true })
87
1/1
✓ Branch 4 taken 1 time.
4 .setNitrousMaximumAfr({ TEST_MAXIMUM_AFR })
88 );
89
2/2
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
3 checkAfrCondition({
90 { {}, false, "default" },
91 { { 0.0f }, true, "0.0" },
92 { { TEST_LAMBDA1 - EPS5D }, true, "TEST_LAMBDA1 - EPS5D" },
93 { { TEST_LAMBDA1 }, true, "TEST_LAMBDA1" },
94 { { TEST_LAMBDA1 + EPS5D }, false, "TEST_LAMBDA1 + EPS5D" },
95 });
96 1 }
97 }
98