Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | #include "pch.h" | |||
2 | #include "turbocharger_speed_converter.h" | |||
3 | ||||
4 | static constexpr engine_type_e ENGINE_TEST_HELPER = engine_type_e::TEST_ENGINE; | |||
5 | ||||
6 | class TurbochargerSpeedConverterTest : public ::testing::Test { | |||
7 | ||||
8 | public: | |||
9 | EngineTestHelper eth; | |||
10 | TurbochargerSpeedConverter dut; | |||
11 | ||||
12 |
1/1✓ Branch 2 taken 2 times.
|
2 | TurbochargerSpeedConverterTest() : eth(ENGINE_TEST_HELPER) { | |
13 | 2 | } | ||
14 | ||||
15 | 2 | void SetUp() override { | ||
16 | 2 | } | ||
17 | ||||
18 | 7 | void SetCoef(float new_coef) { | ||
19 | 7 | engineConfiguration->turboSpeedSensorMultiplier = new_coef; | ||
20 | 7 | } | ||
21 | ||||
22 | 6 | float GetFrequencyBySpeedAndCoef(float speed, float coef) { | ||
23 | 6 | return (speed / coef) / 60; | ||
24 | } | |||
25 | ||||
26 | 6 | void TestForSpeedWithCoef(float expectedSpeed, float coef) | ||
27 | { | |||
28 | 6 | SetCoef(coef); | ||
29 | 6 | auto inputFreq = GetFrequencyBySpeedAndCoef(expectedSpeed, coef); | ||
30 |
1/1✓ Branch 2 taken 6 times.
|
6 | auto result = dut.convert(inputFreq); | |
31 |
2/8✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 7 not taken.
✗ Branch 12 not taken.
✗ Branch 16 not taken.
✗ Branch 19 not taken.
✓ Branch 28 taken 6 times.
✗ Branch 29 not taken.
|
6 | ASSERT_TRUE(result.Valid); | |
32 |
3/8✓ Branch 2 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 9 not taken.
✗ Branch 14 not taken.
✗ Branch 17 not taken.
✓ Branch 24 taken 6 times.
✗ Branch 25 not taken.
|
6 | ASSERT_NEAR(expectedSpeed, result.Value, 0.01f); | |
33 | } | |||
34 | }; | |||
35 | ||||
36 | /* | |||
37 | * Converter must return valid and expected result for setted coef | |||
38 | */ | |||
39 | 4 | TEST_F(TurbochargerSpeedConverterTest, returnExpectedResultForSettedCoef) { | ||
40 | ||||
41 | 1 | TestForSpeedWithCoef(0.0f, 0.5f); | ||
42 | 1 | TestForSpeedWithCoef(0.5f, 0.5f); | ||
43 | 1 | TestForSpeedWithCoef(10.0f, 0.5f); | ||
44 | 1 | TestForSpeedWithCoef(0.0f, 10.0f); | ||
45 | 1 | TestForSpeedWithCoef(0.5f, 10.0f); | ||
46 | 1 | TestForSpeedWithCoef(10.0f, 10.0f); | ||
47 | 1 | } | ||
48 | ||||
49 | /* | |||
50 | * Converter must always return strong float zero if coef == 0.0f | |||
51 | */ | |||
52 | TEST_F(TurbochargerSpeedConverterTest, zeroCoefReturnsZeroSpeedOnAnyInput) { | |||
53 | ||||
54 | SetCoef(0.0f); | |||
55 | ||||
56 | { | |||
57 | auto result = dut.convert(0.0f); | |||
58 | ASSERT_TRUE(result.Valid); | |||
59 | ASSERT_FLOAT_EQ(0.0f, result.Value); | |||
60 | } | |||
61 | ||||
62 | { | |||
63 | auto result = dut.convert(0.5f); | |||
64 | ASSERT_TRUE(result.Valid); | |||
65 | ASSERT_FLOAT_EQ(0.0f, result.Value); | |||
66 | } | |||
67 | ||||
68 | { | |||
69 | auto result = dut.convert(10.0f); | |||
70 | ASSERT_TRUE(result.Valid); | |||
71 | ASSERT_FLOAT_EQ(0.0f, result.Value); | |||
72 | } | |||
73 | } | |||
74 |