From f8e21589fcbe797d634ddcee83257d300dcab570 Mon Sep 17 00:00:00 2001 From: crsz20 Date: Wed, 10 Jul 2024 23:17:14 -0500 Subject: [PATCH] Updated unit testing fixture to add rpm and wheel speed dependencies --- .vscode/settings.json | 69 +++++++++++++++++++ .../ShiftController/shift_controller.hpp | 7 +- Firmware/Shifter_System/Program/Src/app.cpp | 1 + .../Application/shift_controller_tests.cpp | 8 +++ 4 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..1907abf --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,69 @@ +{ + "files.associations": { + "any": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "cinttypes": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "forward_list": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "semaphore": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "stop_token": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp", + "variant": "cpp" + } +} \ No newline at end of file diff --git a/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.hpp b/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.hpp index 2ddad42..998958a 100644 --- a/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.hpp +++ b/Firmware/Shifter_System/Program/Src/Application/ShiftController/shift_controller.hpp @@ -61,8 +61,7 @@ class ShiftController { }; State* current_state_{&neutral_state_}; - int16_t& rpm_; - std::array& wheel_speeds_; + public: ShiftController(int16_t &rpm_observer, @@ -75,13 +74,15 @@ class ShiftController { State* GetState() { return current_state_; } - private: void SetState(State* new_state); LowGear low_gear_state_; Neutral neutral_state_; MidGear mid_gear_state_; HighGear high_gear_state_; + + int16_t& rpm_; + std::array& wheel_speeds_; }; } // namespace application diff --git a/Firmware/Shifter_System/Program/Src/app.cpp b/Firmware/Shifter_System/Program/Src/app.cpp index de24d83..9e7bf71 100644 --- a/Firmware/Shifter_System/Program/Src/app.cpp +++ b/Firmware/Shifter_System/Program/Src/app.cpp @@ -102,6 +102,7 @@ void cppMain() { can_bus->EnableInterruptMode(); } + shift_controller.Run(); } } diff --git a/Firmware/Tests/Src/Application/shift_controller_tests.cpp b/Firmware/Tests/Src/Application/shift_controller_tests.cpp index 7cfde93..563c809 100644 --- a/Firmware/Tests/Src/Application/shift_controller_tests.cpp +++ b/Firmware/Tests/Src/Application/shift_controller_tests.cpp @@ -9,6 +9,14 @@ namespace application { class ShiftControllerWrapper : public ShiftController { public: + + int16_t rpm_; + std::array wheel_speeds_; + + ShiftControllerWrapper() + : ShiftController(rpm_, + wheel_speeds_) { } + bool IsLowGearState() { return dynamic_cast(current_state_) != nullptr; } bool IsNeutralState() { return dynamic_cast(current_state_) != nullptr; } bool IsMidGearState() { return dynamic_cast(current_state_) != nullptr; }