#include "pch.h" #include "vvt.h" using ::testing::StrictMock; using ::testing::Return; TEST(Vvt, TestSetPoint) { EngineTestHelper eth(TEST_ENGINE); // Set up a mock target map StrictMock targetMap; EXPECT_CALL(targetMap, getValue(4321, 55)) .WillOnce(Return(20)); // Mock necessary inputs engine->engineState.fuelingLoad = 55; Sensor::setMockValue(SensorType::Rpm, 4321); VvtController dut; dut.init(0, 0, 0, &targetMap); // Test dut EXPECT_EQ(20, dut.getSetpoint().value_or(0)); } TEST(Vvt, observePlant) { EngineTestHelper eth(TEST_ENGINE); engine->triggerCentral.vvtPosition[0][0] = 23; VvtController dut; dut.init(0, 0, 0, nullptr); EXPECT_EQ(23, dut.observePlant().value_or(0)); } TEST(Vvt, openLoop) { VvtController dut; // No open loop for now EXPECT_EQ(dut.getOpenLoop(10), 0); } TEST(Vvt, ClosedLoopNotInverted) { EngineTestHelper eth(TEST_ENGINE); VvtController dut; dut.init(0, 0, 0, nullptr); engineConfiguration->auxPid[0].pFactor = 1.5f; engineConfiguration->auxPid[0].iFactor = 0; engineConfiguration->auxPid[0].dFactor = 0; engineConfiguration->auxPid[0].offset = 0; // Target of 30 with position 20 should yield positive duty, P=1.5 means 15% duty for 10% error EXPECT_EQ(dut.getClosedLoop(30, 20).value_or(0), 15); } TEST(Vvt, ClosedLoopInverted) { EngineTestHelper eth(TEST_ENGINE); VvtController dut; dut.init(0, 0, 0, nullptr); engineConfiguration->invertVvtControlIntake = true; engineConfiguration->auxPid[0].pFactor = 1.5f; engineConfiguration->auxPid[0].iFactor = 0; engineConfiguration->auxPid[0].dFactor = 0; engineConfiguration->auxPid[0].offset = 0; // Target of -30 with position -20 should yield positive duty, P=1.5 means 15% duty for 10% error EXPECT_EQ(dut.getClosedLoop(-30, -20).value_or(0), 15); }