From eb5123724a44086913c673b40285277b0e9ddf7f Mon Sep 17 00:00:00 2001 From: Comerm28 Date: Mon, 30 Sep 2024 11:07:13 -0400 Subject: [PATCH] up to date --- test/test_systems/tc_mux_v2_testing.h | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/test_systems/tc_mux_v2_testing.h b/test/test_systems/tc_mux_v2_testing.h index 2b15b364..248348d1 100644 --- a/test/test_systems/tc_mux_v2_testing.h +++ b/test/test_systems/tc_mux_v2_testing.h @@ -108,6 +108,41 @@ TEST(TorqueControllerMuxTesting, test_construction_bypass_limits) ASSERT_EQ(test.get_tc_mux_status().output_is_bypassing_limits, true); } +template +void test_with_n_controllers() { + SharedCarState_s state({}, {}, {}, {}, {}, {}); + std::array controller_instances; + std::array controller_ptrs; + std::array error_flags{}; + + for (int i = 0; i < num_controllers; ++i) { + controller_ptrs[i] = static_cast(&controller_instances[i]); + } + + // Instantiate TorqueControllerMux with the current number of controllers + TorqueControllerMux mux(controller_ptrs, error_flags); + + // Test the getDrivetrainCommand method + auto result = mux.getDrivetrainCommand(ControllerMode_e::MODE_0, TorqueLimit_e::TCMUX_FULL_TORQUE, state); + + // Assert no error has occurred + ASSERT_EQ(mux.get_tc_mux_status().current_error, TorqueControllerMuxError::NO_ERROR); +} + +// Test case for different numbers of controllers (hardcoded bc needs a const) +TEST(TorqueControllerMuxTesting, test_variable_length_controllers) +{ + test_with_n_controllers<1>(); + test_with_n_controllers<2>(); + test_with_n_controllers<3>(); + test_with_n_controllers<4>(); + test_with_n_controllers<5>(); + test_with_n_controllers<6>(); + test_with_n_controllers<7>(); + test_with_n_controllers<8>(); + test_with_n_controllers<9>(); + test_with_n_controllers<10>(); +} //logic testing // ensure that swapping to a controller that has a higher desired output speed than previously