From b961944790e036f7157e245ff06bef06d28b9c7b Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Mon, 10 Aug 2020 22:11:25 -0700 Subject: [PATCH] tests --- .../ignition_injection/test_fuel_computer.cpp | 41 +++++++++++++++++++ unit_tests/tests/test_fuel_math.cpp | 2 +- unit_tests/tests/tests.mk | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 unit_tests/tests/ignition_injection/test_fuel_computer.cpp diff --git a/unit_tests/tests/ignition_injection/test_fuel_computer.cpp b/unit_tests/tests/ignition_injection/test_fuel_computer.cpp new file mode 100644 index 0000000000..9b666f1237 --- /dev/null +++ b/unit_tests/tests/ignition_injection/test_fuel_computer.cpp @@ -0,0 +1,41 @@ +#include "engine_test_helper.h" + +// sneaky... +#define protected public +#include "fuel_computer.h" +#include "mocks.h" + +#include "gtest/gtest.h" + +using ::testing::FloatEq; + +class MockFuelComputer : public FuelComputerBase { +public: + MOCK_METHOD(float, getStoichiometricRatio, (), (const, override)); + MOCK_METHOD(float, getTargetLambda, (int rpm, float load), (const, override)); +}; + +TEST(FuelComputer, getCycleFuel) { + WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + + MockFuelComputer dut; + INJECT_ENGINE_REFERENCE(&dut); + + EXPECT_CALL(dut, getStoichiometricRatio()) + .WillOnce(Return(3.0f)); + EXPECT_CALL(dut, getTargetLambda(1000, FloatEq(0.8f))) + .WillOnce(Return(5.0f)); + + auto result = dut.getCycleFuel(7.0f, 1000, 0.8f); + EXPECT_FLOAT_EQ(result, 7.0f / (5 * 3)); +} + +TEST(FuelComputer, LambdaLookup) { + MockVp3d afrTable; + FuelComputer dut(afrTable); + + EXPECT_CALL(afrTable, getValue(1500, FloatEq(0.7f))) + .WillOnce(Return(14.7f)); + + EXPECT_FLOAT_EQ(dut.getTargetLambda(1500, 0.7f), 1.0f); +} diff --git a/unit_tests/tests/test_fuel_math.cpp b/unit_tests/tests/test_fuel_math.cpp index b95084e603..a80d17ad5a 100644 --- a/unit_tests/tests/test_fuel_math.cpp +++ b/unit_tests/tests/test_fuel_math.cpp @@ -78,7 +78,7 @@ TEST(AirmassModes, AlphaNFailedTps) { EXPECT_EQ(result.CylinderAirmass, 0); } -TEST(misc, MafNormal) { +TEST(AirmassModes, MafNormal) { WITH_ENGINE_TEST_HELPER(FORD_ASPIRE_1996); engineConfiguration->fuelAlgorithm = LM_REAL_MAF; engineConfiguration->injector.flow = 200; diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index bac33b4443..470c410b12 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -12,6 +12,7 @@ TESTS_SRC_CPP = \ tests/ignition_injection/test_multispark.cpp \ tests/ignition_injection/test_ignition_scheduling.cpp \ tests/ignition_injection/test_fuelCut.cpp \ + tests/ignition_injection/test_fuel_computer.cpp \ tests/test_util.cpp \ tests/test_ion.cpp \ tests/test_aux_valves.cpp \