LCOV - code coverage report
Current view: top level - unit_tests/tests/ignition_injection - test_fuel_computer.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 33 33 100.0 %
Date: 2024-04-25 02:23:43 Functions: 14 14 100.0 %

          Line data    Source code
       1             : #include "pch.h"
       2             : 
       3             : // sneaky...
       4             : #define protected public
       5             : #include "fuel_computer.h"
       6             : 
       7             : using ::testing::FloatEq;
       8             : 
       9             : class MockFuelComputer : public FuelComputerBase {
      10             : public:
      11           2 :         MOCK_METHOD(float, getStoichiometricRatio, (), (const, override));
      12           2 :         MOCK_METHOD(float, getTargetLambda, (int rpm, float load), (const, override));
      13           2 :         MOCK_METHOD(float, getTargetLambdaLoadAxis, (float defaultLoad), (const, override));
      14             : };
      15             : 
      16           4 : TEST(FuelComputer, getCycleFuel) {
      17           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      18             : 
      19           1 :         MockFuelComputer dut;
      20             : 
      21           3 :         EXPECT_CALL(dut, getTargetLambdaLoadAxis(FloatEq(0.8f)))
      22           3 :                 .WillOnce(Return(0.8f));
      23           3 :         EXPECT_CALL(dut, getStoichiometricRatio())
      24           3 :                 .WillOnce(Return(3.0f));
      25           3 :         EXPECT_CALL(dut, getTargetLambda(1000, FloatEq(0.8f)))
      26           3 :                 .WillOnce(Return(5.0f));
      27             : 
      28           1 :         auto result = dut.getCycleFuel(7.0f, 1000, 0.8f);
      29           1 :         EXPECT_FLOAT_EQ(result, 7.0f / (5 * 3));
      30           2 : }
      31             : 
      32           4 : TEST(FuelComputer, FlexFuel) {
      33           1 :         EngineTestHelper eth(engine_type_e::TEST_ENGINE);
      34             : 
      35           1 :         FuelComputer dut;
      36             : 
      37             :         // easier values for testing
      38           1 :         engineConfiguration->stoichRatioPrimary = 15;
      39           1 :         engineConfiguration->stoichRatioSecondary = 10;
      40             : 
      41             :         // No sensor -> returns primary
      42           1 :         Sensor::resetMockValue(SensorType::FuelEthanolPercent);
      43           1 :         EXPECT_FLOAT_EQ(15.0f, dut.getStoichiometricRatio());
      44             : 
      45             :         // E0 -> primary afr
      46           1 :         Sensor::setMockValue(SensorType::FuelEthanolPercent, 0);
      47           1 :         EXPECT_FLOAT_EQ(15.0f, dut.getStoichiometricRatio());
      48             : 
      49             :         // E50 -> half way between
      50           1 :         Sensor::setMockValue(SensorType::FuelEthanolPercent, 50);
      51           1 :         EXPECT_FLOAT_EQ(12.5f, dut.getStoichiometricRatio());
      52             : 
      53             :         // E100 -> secondary afr
      54           1 :         Sensor::setMockValue(SensorType::FuelEthanolPercent, 100);
      55           1 :         EXPECT_FLOAT_EQ(10.0f, dut.getStoichiometricRatio());
      56             : 
      57             :         // E(-10) -> clamp to primary
      58           1 :         Sensor::setMockValue(SensorType::FuelEthanolPercent, -10);
      59           1 :         EXPECT_FLOAT_EQ(15.0f, dut.getStoichiometricRatio());
      60             : 
      61             :         // E110 -> clamp to secondary
      62           1 :         Sensor::setMockValue(SensorType::FuelEthanolPercent, 110);
      63           1 :         EXPECT_FLOAT_EQ(10.0f, dut.getStoichiometricRatio());
      64           2 : }

Generated by: LCOV version 1.14