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 TpsConditionTestData { | |||
13 | const std::optional<float> tps; | |||
14 | const bool expectedTpsCondition; | |||
15 | const char* const context; | |||
16 | }; | |||
17 | ||||
18 | class NitrousTpsConditionTest : public TestBase<> { | |||
19 | protected: | |||
20 | static constexpr int TEST_MIN_TPS = 34; | |||
21 | ||||
22 | void checkTpsCondition(const std::vector<TpsConditionTestData>& testData); | |||
23 | }; | |||
24 | ||||
25 | 5 | void NitrousTpsConditionTest::checkTpsCondition(const std::vector<TpsConditionTestData>& testData) { | ||
26 |
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 TpsConditionTestData& item: testData) { |
27 |
1/1✓ Branch 1 taken 25 times.
|
25 | updateApp(item.tps, &TestBase::periodicSlowCallback); | |
28 |
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>().isNitrousTpsCondition, item.expectedTpsCondition) | |
29 |
0/1✗ Branch 1 not taken.
|
25 | << item.context; | |
30 | } | |||
31 | 5 | } | ||
32 | ||||
33 | 4 | TEST_F(NitrousTpsConditionTest, checkDefault) { | ||
34 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkTpsCondition({ | |
35 | { {}, false, "default" }, | |||
36 | { { 0.0f }, false, "0.0" }, | |||
37 | { { TEST_MIN_TPS - EPS5D }, false, "TEST_MIN_TPS - EPS5D" }, | |||
38 | { { TEST_MIN_TPS }, false, "TEST_MIN_TPS" }, | |||
39 | { { TEST_MIN_TPS + EPS5D }, false, "TEST_MIN_TPS + EPS5D" }, | |||
40 | }); | |||
41 | 1 | } | ||
42 | ||||
43 | 4 | TEST_F(NitrousTpsConditionTest, checkDefaultWithDisabledNitrousControl) { | ||
44 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ false })); | |
45 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkTpsCondition({ | |
46 | { {}, false, "default" }, | |||
47 | { { 0.0f }, false, "0.0" }, | |||
48 | { { TEST_MIN_TPS - EPS5D }, false, "TEST_MIN_TPS - EPS5D" }, | |||
49 | { { TEST_MIN_TPS }, false, "TEST_MIN_TPS" }, | |||
50 | { { TEST_MIN_TPS + EPS5D }, false, "TEST_MIN_TPS + EPS5D" }, | |||
51 | }); | |||
52 | 1 | } | ||
53 | ||||
54 | 4 | TEST_F(NitrousTpsConditionTest, checkDefaultWithEnabledNitrousControl) { | ||
55 |
2/2✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | setUpEngineConfiguration(EngineConfig().setNitrousControlEnabled({ true })); | |
56 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkTpsCondition({ | |
57 | { {}, false, "default" }, | |||
58 | { { 0.0f }, false, "0.0" }, | |||
59 | { { engine_configuration_defaults::NITROUS_MINIMUM_TPS - EPS5D }, false, "NITROUS_MINIMUM_TPS - EPS5D" }, | |||
60 | { { engine_configuration_defaults::NITROUS_MINIMUM_TPS }, true, "NITROUS_MINIMUM_TPS" }, | |||
61 | { { engine_configuration_defaults::NITROUS_MINIMUM_TPS + EPS5D }, true, "NITROUS_MINIMUM_TPS + EPS5D" }, | |||
62 | }); | |||
63 | 1 | } | ||
64 | ||||
65 | 4 | TEST_F(NitrousTpsConditionTest, checkZeroMinimumTps) { | ||
66 |
1/1✓ Branch 2 taken 1 time.
|
2 | setUpEngineConfiguration( | |
67 | 1 | EngineConfig() | ||
68 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setNitrousControlEnabled({ true }) | |
69 |
1/1✓ Branch 5 taken 1 time.
|
4 | .setNitrousMinimumTps(0.0f) | |
70 | ); | |||
71 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkTpsCondition({ | |
72 | { {}, true, "default" }, | |||
73 | { { 0.0f }, true, "0.0" }, | |||
74 | { { TEST_MIN_TPS - EPS5D }, true, "TEST_MIN_TPS - EPS5D" }, | |||
75 | { { TEST_MIN_TPS }, true, "TEST_MIN_TPS" }, | |||
76 | { { TEST_MIN_TPS + EPS5D }, true, "TEST_MIN_TPS + EPS5D" }, | |||
77 | }); | |||
78 | 1 | } | ||
79 | ||||
80 | 4 | TEST_F(NitrousTpsConditionTest, checkMinimumTps) { | ||
81 |
1/1✓ Branch 2 taken 1 time.
|
2 | setUpEngineConfiguration( | |
82 | 1 | EngineConfig() | ||
83 |
1/1✓ Branch 6 taken 1 time.
|
3 | .setNitrousControlEnabled({ true }) | |
84 |
1/1✓ Branch 4 taken 1 time.
|
4 | .setNitrousMinimumTps({ TEST_MIN_TPS }) | |
85 | ); | |||
86 |
2/2✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
|
3 | checkTpsCondition({ | |
87 | { {}, false, "default" }, | |||
88 | { { 0.0f }, false, "0.0" }, | |||
89 | { { TEST_MIN_TPS - EPS5D }, false, "TEST_MIN_TPS - EPS5D" }, | |||
90 | { { TEST_MIN_TPS }, true, "TEST_MIN_TPS" }, | |||
91 | { { TEST_MIN_TPS + EPS5D }, true, "TEST_MIN_TPS + EPS5D" }, | |||
92 | }); | |||
93 | 1 | } | ||
94 | } | |||
95 |