# Simulator Unit Tests Unit tests for the `Simulator` class are implemented in `src/g2_2025_odometry_pkg/test/test_simulator.cpp` using Google Test and ROS2 test utilities. The tests validate interval-based value generation with different interpolation types. ## Test Cases ### 1. ConstantInterval **Description:** Verifies constant interpolation returns the same value throughout the interval. - **Test Configuration:** - Single interval: t=[0, 10], y_start=5.0 - Type: constant - **Expected Result:** - Value is 5.0 at t=0, t=5, t=10 - Value holds at 5.0 after interval (t=15) ### 2. LinearInterval **Description:** Tests linear interpolation between start and end values. - **Test Configuration:** - Single interval: t=[0, 10], y_start=0.0, y_end=10.0 - Type: linear - **Expected Result:** - Value is 0.0 at t=0 - Value is 5.0 at t=5 - Value is 10.0 at t=10 - Value holds at 10.0 after interval (t=15) ### 3. QuadraticInterval **Description:** Tests quadratic (Lagrange) interpolation through 3 points. - **Test Configuration:** - Single interval: t=[0, 10], y_start=0.0, y_end=0.0, t_mid=5.0, y_mid=10.0 - Type: quadratic - **Expected Result:** - Value is 0.0 at t=0 - Value is 10.0 at t=5 (peak) - Value is 0.0 at t=10 - Value holds at 0.0 after interval (t=15) ### 4. MultipleIntervals **Description:** Tests behavior with multiple non-overlapping intervals and gaps. - **Test Configuration:** - Interval 0: t=[0, 5], constant 5.0 - Interval 1: t=[10, 15], constant 10.0 - Gap between t=5 and t=10 - **Expected Result:** - Value is 5.0 at t=2.5 (first interval) - Value holds at 5.0 in gap (t=7.5) - Value is 10.0 at t=12.5 (second interval) - Value holds at 10.0 after all intervals (t=20) ### 5. ValueBeforeIntervals **Description:** Tests behavior when querying time before any interval starts. - **Test Configuration:** - Single interval: t=[10, 20] - **Expected Result:** - Value is 0.0 at t=5 (before interval starts) ### 6. NonExistentChannel **Description:** Tests graceful handling of queries for unconfigured channels. - **Test Action:** Query `get_object_value("nonexistent_channel", 5.0)` - **Expected Result:** Returns 0.0 ### 7. OverlappingIntervalsThrowsException **Description:** Verifies that overlapping intervals are detected and rejected. - **Test Configuration:** - Interval 0: t=[0, 10] - Interval 1: t=[5, 15] (overlaps) - **Expected Result:** Constructor throws `std::runtime_error` ### 8. MaxIntervalsLimit **Description:** Tests that `max_intervals` parameter limits loaded intervals. - **Test Configuration:** - max_intervals=2 - num_intervals=3 (defines 3 intervals) - **Expected Result:** - Only first 2 intervals are loaded - Third interval values default to holding second interval's end value ## Test Infrastructure The test class `SimulatorTest` provides: - Static `SetUpTestSuite()` and `TearDownTestSuite()` for ROS2 init/shutdown - Helper method `createNodeWithParams()` for creating nodes with parameter overrides