fome-fw/unit_tests/tests/ignition_injection/test_fuel_computer.cpp

42 lines
991 B
C++
Raw Normal View History

2020-08-10 22:11:25 -07:00
#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);
}