2021-09-19 17:50:11 -07:00
|
|
|
#include "pch.h"
|
|
|
|
#include "turbocharger_speed_converter.h"
|
|
|
|
|
|
|
|
static constexpr engine_type_e ENGINE_TEST_HELPER = TEST_ENGINE;
|
|
|
|
|
|
|
|
class TurbochargerSpeedConverterTest : public ::testing::Test {
|
|
|
|
|
|
|
|
public:
|
2021-11-15 16:44:39 -08:00
|
|
|
EngineTestHelper eth;
|
2021-09-19 17:50:11 -07:00
|
|
|
TurbochargerSpeedConverter dut;
|
|
|
|
|
2021-11-15 16:44:39 -08:00
|
|
|
TurbochargerSpeedConverterTest()
|
|
|
|
: eth(ENGINE_TEST_HELPER, std::unordered_map<SensorType, float>{}) {
|
2021-09-19 17:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetUp() override {
|
2021-11-15 16:44:39 -08:00
|
|
|
EXPAND_EngineTestHelper;
|
2021-11-15 03:44:40 -08:00
|
|
|
dut.inject(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2021-09-19 17:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetCoef(float new_coef) {
|
|
|
|
dut.engineConfiguration->turboSpeedSensorMultiplier = new_coef;
|
|
|
|
}
|
|
|
|
|
|
|
|
float GetFrequencyBySpeedAndCoef(float speed, float coef) {
|
2021-09-20 12:39:41 -07:00
|
|
|
return (speed / coef) / 60;
|
2021-09-19 17:50:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestForSpeedWithCoef(float expectedSpeed, float coef)
|
|
|
|
{
|
|
|
|
SetCoef(coef);
|
|
|
|
auto inputFreq = GetFrequencyBySpeedAndCoef(expectedSpeed, coef);
|
|
|
|
auto result = dut.convert(inputFreq);
|
|
|
|
ASSERT_TRUE(result.Valid);
|
|
|
|
ASSERT_NEAR(expectedSpeed, result.Value, 0.01f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converter must return valid and expected result for setted coef
|
|
|
|
*/
|
|
|
|
TEST_F(TurbochargerSpeedConverterTest, returnExpectedResultForSettedCoef) {
|
|
|
|
|
|
|
|
TestForSpeedWithCoef(0.0f, 0.5f);
|
|
|
|
TestForSpeedWithCoef(0.5f, 0.5f);
|
|
|
|
TestForSpeedWithCoef(10.0f, 0.5f);
|
|
|
|
TestForSpeedWithCoef(0.0f, 10.0f);
|
|
|
|
TestForSpeedWithCoef(0.5f, 10.0f);
|
|
|
|
TestForSpeedWithCoef(10.0f, 10.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Converter must always return strong float zero if coef == 0.0f
|
|
|
|
*/
|
|
|
|
TEST_F(TurbochargerSpeedConverterTest, zeroCoefReturnsZeroSpeedOnAnyInput) {
|
|
|
|
|
|
|
|
SetCoef(0.0f);
|
|
|
|
|
|
|
|
{
|
|
|
|
auto result = dut.convert(0.0f);
|
|
|
|
ASSERT_TRUE(result.Valid);
|
|
|
|
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto result = dut.convert(0.5f);
|
|
|
|
ASSERT_TRUE(result.Valid);
|
|
|
|
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto result = dut.convert(10.0f);
|
|
|
|
ASSERT_TRUE(result.Valid);
|
|
|
|
ASSERT_FLOAT_EQ(0.0f, result.Value);
|
|
|
|
}
|
2021-11-15 16:44:39 -08:00
|
|
|
}
|