Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // | |||
2 | // Created by kifir on 11/28/24. | |||
3 | // | |||
4 | ||||
5 | #include "pch.h" | |||
6 | ||||
7 | #include "util/test_base.h" | |||
8 | ||||
9 | namespace { | |||
10 | struct MapConditionTestData { | |||
11 | const std::optional<float> map; | |||
12 | const bool expectedMapCondition; | |||
13 | const char* const context; | |||
14 | }; | |||
15 | ||||
16 | class NitrousMapConditionTest : public TestBase<> { | |||
17 | protected: | |||
18 | static constexpr int TEST_MAX_MAP = 45; | |||
19 | ||||
20 | void checkMapCondition(const std::vector<MapConditionTestData>& testData); | |||
21 | }; | |||
22 | ||||
23 | 5 | void NitrousMapConditionTest::checkMapCondition(const std::vector<MapConditionTestData>& testData) { | ||
24 |
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 MapConditionTestData& item: testData) { |
25 |
1/1✓ Branch 1 taken 25 times.
|
25 | updateMap(item.map, &TestBase::periodicSlowCallback); | |
26 |
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>().isNitrousMapCondition, item.expectedMapCondition) | |
27 |
0/1✗ Branch 1 not taken.
|
25 | << item.context; | |
28 | } | |||
29 | 5 | } | ||
30 | ||||
31 | 4 | TEST_F(NitrousMapConditionTest, checkDefault) { | ||
32 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkMapCondition({ | |
33 | { {}, false, "default" }, | |||
34 | { { 0.0f }, false, "0.0" }, | |||
35 | { { TEST_MAX_MAP - EPS5D }, false, "TEST_MAX_MAP - EPS5D" }, | |||
36 | { { TEST_MAX_MAP }, false, "TEST_MAX_MAP" }, | |||
37 | { { TEST_MAX_MAP + EPS5D }, false, "TEST_MAX_MAP + EPS5D" }, | |||
38 | }); | |||
39 | 1 | } | ||
40 | ||||
41 | 4 | TEST_F(NitrousMapConditionTest, checkDefaultWithDisabledNitrousControl) { | ||
42 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ false })); | |
43 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkMapCondition({ | |
44 | { {}, false, "default" }, | |||
45 | { { 0.0f }, false, "0.0" }, | |||
46 | { { TEST_MAX_MAP - EPS5D }, false, "TEST_MAX_MAP - EPS5D" }, | |||
47 | { { TEST_MAX_MAP }, false, "TEST_MAX_MAP" }, | |||
48 | { { TEST_MAX_MAP + EPS5D }, false, "TEST_MAX_MAP + EPS5D" }, | |||
49 | }); | |||
50 | 1 | } | ||
51 | ||||
52 | 4 | TEST_F(NitrousMapConditionTest, checkDefaultWithEnabledNitrousControl) { | ||
53 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ true })); | |
54 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkMapCondition({ | |
55 | { {}, true, "default" }, | |||
56 | { { 0.0f }, true, "0.0" }, | |||
57 | { { TEST_MAX_MAP - EPS5D }, true, "TEST_MAX_MAP - EPS5D" }, | |||
58 | { { TEST_MAX_MAP }, true, "TEST_MAX_MAP" }, | |||
59 | { { TEST_MAX_MAP + EPS5D }, true, "TEST_MAX_MAP + EPS5D" }, | |||
60 | }); | |||
61 | 1 | } | ||
62 | ||||
63 | 4 | TEST_F(NitrousMapConditionTest, checkZeroMaximumMap) { | ||
64 |
1/1✓ Branch 2 taken 1 time.
|
2 | setUpEngineConfiguration( | |
65 | 1 | EngineConfig() | ||
66 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setNitrousControlEnabled({ true }) | |
67 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setNitrousMaximumMap(0.0f) | |
68 | ); | |||
69 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkMapCondition({ | |
70 | { {}, true, "default" }, | |||
71 | { { 0.0f }, true, "0.0" }, | |||
72 | { { TEST_MAX_MAP - EPS5D }, true, "TEST_MAX_MAP - EPS5D" }, | |||
73 | { { TEST_MAX_MAP }, true, "TEST_MAX_MAP" }, | |||
74 | { { TEST_MAX_MAP + EPS5D }, true, "TEST_MAX_MAP + EPS5D" }, | |||
75 | }); | |||
76 | 1 | } | ||
77 | ||||
78 | 4 | TEST_F(NitrousMapConditionTest, checkMaximumMap) { | ||
79 |
1/1✓ Branch 2 taken 1 time.
|
2 | setUpEngineConfiguration( | |
80 | 1 | EngineConfig() | ||
81 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setNitrousControlEnabled({ true }) | |
82 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setNitrousMaximumMap({ TEST_MAX_MAP }) | |
83 | ); | |||
84 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkMapCondition({ | |
85 | { {}, false, "default" }, | |||
86 | { { 0.0f }, true, "0.0" }, | |||
87 | { { TEST_MAX_MAP - EPS5D }, true, "TEST_MAX_MAP - EPS5D" }, | |||
88 | { { TEST_MAX_MAP }, true, "TEST_MAX_MAP" }, | |||
89 | { { TEST_MAX_MAP + EPS5D }, false, "TEST_MAX_MAP + EPS5D" }, | |||
90 | }); | |||
91 | 1 | } | ||
92 | } | |||
93 |