Skip to content

Commit

Permalink
variable controller count
Browse files Browse the repository at this point in the history
  • Loading branch information
mileskent committed Sep 29, 2024
1 parent 2be1f0d commit 2efbfff
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/test_systems/tc_mux_v2_testing.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,45 @@ TEST(TorqueControllerMuxTesting, test_null_pointer_error_state)
}
ASSERT_EQ(test.get_tc_mux_status().current_error, TorqueControllerMuxError::ERROR_CONTROLLER_NULL_POINTER);
}


template<int num_controllers>
void test_with_n_controllers() {
SharedCarState_s state({}, {}, {}, {}, {}, {});
std::array<TestControllerType, num_controllers> controller_instances; // Use std::array instead of std::vector
std::array<Controller*, num_controllers> controller_ptrs; // Use std::array for pointers
std::array<bool, num_controllers> error_flags{}; // Default-initialize to false

// Fill the controller pointer array
for (int i = 0; i < num_controllers; ++i) {
controller_ptrs[i] = static_cast<Controller*>(&controller_instances[i]);
}

// Instantiate TorqueControllerMux with the current number of controllers
TorqueControllerMux<num_controllers> 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>();
}



#endif // __TC_MUX_V2_TESTING_H__

0 comments on commit 2efbfff

Please sign in to comment.