Line data Source code
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 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 6 : auto result = dut.convert(inputFreq); 31 6 : ASSERT_TRUE(result.Valid); 32 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 4 : TEST_F(TurbochargerSpeedConverterTest, zeroCoefReturnsZeroSpeedOnAnyInput) { 53 : 54 1 : SetCoef(0.0f); 55 : 56 : { 57 1 : auto result = dut.convert(0.0f); 58 1 : ASSERT_TRUE(result.Valid); 59 1 : ASSERT_FLOAT_EQ(0.0f, result.Value); 60 : } 61 : 62 : { 63 1 : auto result = dut.convert(0.5f); 64 1 : ASSERT_TRUE(result.Valid); 65 1 : ASSERT_FLOAT_EQ(0.0f, result.Value); 66 : } 67 : 68 : { 69 1 : auto result = dut.convert(10.0f); 70 1 : ASSERT_TRUE(result.Valid); 71 1 : ASSERT_FLOAT_EQ(0.0f, result.Value); 72 : } 73 : }