diff --git a/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.cpp b/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.cpp index 486aa70..bbfa19b 100644 --- a/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.cpp +++ b/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.cpp @@ -34,7 +34,7 @@ void ShiftController::LowGear::Enter(ShiftController& context) { } void ShiftController::LowGear::Compute(ShiftController& context) { - + } void ShiftController::LowGear::Exit(ShiftController& context) { @@ -50,7 +50,9 @@ void ShiftController::Neutral::Enter(ShiftController& context) { } void ShiftController::Neutral::Compute(ShiftController& context) { - + if(context.neutral_switch_->Read()) { + context.SetState(&context.low_gear_state_); + } } void ShiftController::Neutral::Exit(ShiftController& context) { diff --git a/Firmware/Tests/Src/Application/shift_controller_tests.cpp b/Firmware/Tests/Src/Application/shift_controller_tests.cpp index 563c809..383a182 100644 --- a/Firmware/Tests/Src/Application/shift_controller_tests.cpp +++ b/Firmware/Tests/Src/Application/shift_controller_tests.cpp @@ -5,17 +5,24 @@ // DFR Custom Dependencies #include "../../../Shifter_System/Program/Src/Application/ShiftController/shift_controller.hpp" +class MockGpio : public platform::IGpio { +public: + MOCK_METHOD(bool, Read, (), (override)); + MOCK_METHOD(void, Write, (bool signal), (override)); + MOCK_METHOD(bool, ToggleDetected, (), (override)); +}; + + namespace application { class ShiftControllerWrapper : public ShiftController { public: - - int16_t rpm_; - std::array wheel_speeds_; - - ShiftControllerWrapper() - : ShiftController(rpm_, - wheel_speeds_) { } + ShiftControllerWrapper(int16_t &rpm, + std::array &wheel_speeds, + std::shared_ptr neutral_switch) + : ShiftController(rpm, + wheel_speeds, + neutral_switch) { } bool IsLowGearState() { return dynamic_cast(current_state_) != nullptr; } bool IsNeutralState() { return dynamic_cast(current_state_) != nullptr; } @@ -26,11 +33,36 @@ class ShiftControllerWrapper : public ShiftController { class ShiftControllerFixture : public testing::Test { protected: - ShiftControllerWrapper shift_controller_; + int16_t rpm; + std::array wheel_speeds_; + std::shared_ptr neutral_switch_ = std::make_shared(); + ShiftControllerWrapper shift_controller_{rpm, wheel_speeds_, neutral_switch_}; }; TEST_F(ShiftControllerFixture, DefaultToNeutralState) { EXPECT_TRUE(shift_controller_.IsNeutralState()); } +TEST_F(ShiftControllerFixture, TransitionToLowGearState) { + EXPECT_TRUE(shift_controller_.IsNeutralState()); + + EXPECT_CALL(*neutral_switch_, Read()) + .Times(1) + .WillOnce(::testing::Return(true)); + + shift_controller_.Run(); + EXPECT_TRUE(shift_controller_.IsLowGearState()); +} + +TEST_F(ShiftControllerFixture, RemainNeutralState) { + EXPECT_TRUE(shift_controller_.IsNeutralState()); + + EXPECT_CALL(*neutral_switch_, Read()) + .Times(1) + .WillOnce(::testing::Return(false)); + + shift_controller_.Run(); + EXPECT_TRUE(shift_controller_.IsNeutralState()); +} + } // namespace application