fome-fw/unit_tests/tests/sensor/test_vehicle_speed_converte...

75 lines
1.6 KiB
C++
Raw Normal View History

Vehicle speed switching to frequency sensor #3106 (#3148) * Add vehicle_speed_converter.h with realization. * Add test_vehicle_speed_converter.cpp with realization. * Add test_vehicle_speed_converter.cpp to Makefile * Edit "VehicleSpeedSensor" from function pointer sensor to frequency sensor * Fix "VehicleSpeedSensor" init function args * Remove "VehicleSpeedConverter" empty constructor * Edit vehicle_speed_converter.h code style * Fix args and engine injection in "VehicleSpeedSensor" initialization procedure * Remove old "Vehicle Speed" module initialization * Revert "Remove old "Vehicle Speed" module initialization" This reverts commit 100b7caa8c615c20eed3d0c23a49824b4e556148. * Remove old "Vehicle Speed" module initialization pieces * Revert "Revert "Remove old "Vehicle Speed" module initialization"" This reverts commit f559a726f1f7f5a7acacd1b6517e571743e84327. * Debug changes * Revert "Debug changes" This reverts commit f7e2be1a8a46c6f3f93f14f002b2f2db539da8e2. * Another debug changes * More debug changes * And more debug changes. * Revert "Another debug changes" This reverts commit 914fbb1df42c37e4b5ecbb119bb45e7cffdf4064. * Revert "More debug changes" This reverts commit 0b2d96d461c3cd9b0f1ae97ed110b8effe6b0cc6. * Revert "And more debug changes." This reverts commit 06ae8daded0e6e1c025e4e5058b47283f4adfe92. * Add "Vehicle Speed" sensor reconfiguration * Revert "Add "Vehicle Speed" sensor reconfiguration" This reverts commit a089a6d563dd710004ce1a7da1744b0b4b90c3b1. * Revert "Revert "Add "Vehicle Speed" sensor reconfiguration"" This reverts commit 7b2bb8af4b3caa547236ca59e4c4bdb3ac1200cc. * Debug changes * Another debug changes * Fix another debug changes * Another debug changes 2 * Revert "Another debug changes 2" This reverts commit cfad55141eec125b2f1d35fb95d9f46b54f666b6. * Revert "Fix another debug changes" This reverts commit 9bc2c74a3be6fd896827ff48cf4580e7657529c0. * Revert "Another debug changes" This reverts commit 4337ed8cad8dff508d093944eb3f75e9a69e4a77. * Edit class FrequencySensor, make it more RAII * Debug changes * Debug changes 2 * Debug changes 3 * Revert "Debug changes 3" This reverts commit 52a7054c122b5157540fe45a055a84b57478d722. * Revert "Debug changes 2" This reverts commit dec79fb913344ccb4b8614910ad62e6c129a243e. * Revert "Debug changes" This reverts commit eb08d7a529b55ba397a7dd2c154b76eab42f212b. * Revert "Edit class FrequencySensor, make it more RAII" This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Citroen Berlingo" engine config. This reverts commit 3a0bb1d3f1dd23c1b04e4cc1c526cfdc67ae86a3. * Remove VSS pin definition in "Dodge Neon" engine config Co-authored-by: alxrMironov <330OMcorporative>
2021-08-23 21:55:41 -07:00
#include "pch.h"
#include "vehicle_speed_converter.h"
static constexpr engine_type_e ENGINE_TEST_HELPER = TEST_ENGINE;
class VehicleSpeedConverterTest : public ::testing::Test {
public:
VehicleSpeedConverter dut;
VehicleSpeedConverterTest(){
}
void SetUp() override {
WITH_ENGINE_TEST_HELPER(ENGINE_TEST_HELPER);
INJECT_ENGINE_REFERENCE(&dut);
}
void SetCoef(float new_coef) {
dut.engineConfiguration->vehicleSpeedCoef = new_coef;
}
float GetFrequencyBySpeedAndCoef(float speed, float coef) {
return (speed / coef);
}
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(VehicleSpeedConverterTest, 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(VehicleSpeedConverterTest, 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);
}
}