From 2cd95173d309c6e607a897f8305f04433043f5cd Mon Sep 17 00:00:00 2001 From: Wessel Tip Date: Mon, 3 Nov 2025 12:11:58 +0100 Subject: [PATCH] docs: Update test documentation - Changed directories to TNC (Tilmann Naming Convention) - Updated `DatabaseManager` with new IMU methods - Added `IMUDatabaseWriter` test documentation --- doc/tests/ConfigManager.md | 2 +- doc/tests/DatabaseManager.md | 44 ++++++---------------------------- doc/tests/IMUDatabaseWriter.md | 18 ++++++++++++++ 3 files changed, 26 insertions(+), 38 deletions(-) create mode 100644 doc/tests/IMUDatabaseWriter.md diff --git a/doc/tests/ConfigManager.md b/doc/tests/ConfigManager.md index 71cb9a8..e0c6208 100644 --- a/doc/tests/ConfigManager.md +++ b/doc/tests/ConfigManager.md @@ -1,6 +1,6 @@ # Config Manager Unit Tests -Unit tests for `ConfigManager` are implemented in `src/g2_2025_grade_calculator_pkg/test/ConfigManager.test.cpp` using Google Test and ROS2 test utilities. The tests use temporary TOML files to validate configuration loading and parsing functionality. +Unit tests for `ConfigManager` are implemented in `src/g2_2025_imu_reader_pkg/test/ConfigManager.test.cpp` using Google Test and ROS2 test utilities. The tests use temporary TOML files to validate configuration loading and parsing functionality. ## Test Cases diff --git a/doc/tests/DatabaseManager.md b/doc/tests/DatabaseManager.md index 7a5abd6..7747675 100644 --- a/doc/tests/DatabaseManager.md +++ b/doc/tests/DatabaseManager.md @@ -1,6 +1,6 @@ # Database Manager Unit Tests -Unit tests for `DatabaseManager` are implemented in `src/g2_2025_grade_calculator_pkg/test/DatabaseManager.test.cpp` using Google Test and ROS2 test utilities. The tests are designed to work reliably whether a database connection is available or not, focusing on error handling and method behavior validation. +Unit tests for `DatabaseManager` are implemented in `src/g2_2025_imu_reader_pkg/test/DatabaseManager.test.cpp` using Google Test and ROS2 test utilities. The tests are designed to work reliably whether a database connection is available or not, focusing on error handling and method behavior validation. ## Test Cases @@ -22,42 +22,12 @@ Unit tests for `DatabaseManager` are implemented in `src/g2_2025_grade_calculato **Description:** Verifies retrieval of pending student-course combinations that need exam results. -- **Test Action:** Call `queue_pending_combinations()` -- **Expected Result:** Returns valid vector (empty if no database connection, populated if connected) +- Test action: Call `store_imu_data(linear_x, linear_y, linear_z, ang_x, ang_y, ang_z)` without an active DB connection. +- Expected result: Returns `false` and does not throw — method must check connection status before DB operations. -### 4. StoreExamResultTest +### 4. CreateTablesNoCrash -**Description:** Tests exam result storage with graceful handling of connection states. +Description: Verifies calling `create_tables()` without an active connection is safe. -- **Test Action:** - - Student: `"TestStudent"` - - Course: `"TestCourse"` - - Grade: `85` -- **Expected Result:** Returns `false` if no connection, `true` if connected and successful - -### 5. EnrollStudentTest - -**Description:** Tests student enrollment into courses. - -- **Test Action:** - - StudentCourse object with test data -- **Expected Result:** Returns `false` if no connection, `true` if connected and successful - -### 6. GetFinalGradeTest - -**Description:** Tests final grade retrieval for non-existent student-course combinations. - -- **Test Action:** - - Student: `"NonExistentStudent"` - - Course: `"NonExistentCourse"` -- **Expected Result:** Returns `-1` (no results found or no connection) - -### 7. StoreFinalResultTest - -**Description:** Tests storing calculated final course results. - -- **Test Action:** - - StudentCourse object - - Exam count: `3` - - Final grade: `75` -- **Expected Result:** Returns `false` if no connection, `true` if connected and successful +- Test action: Call `create_tables()` on a manager that is not connected. +- Expected result: No exception thrown; the function should be a no-op when no DB connection exists. diff --git a/doc/tests/IMUDatabaseWriter.md b/doc/tests/IMUDatabaseWriter.md new file mode 100644 index 0000000..1f3e24e --- /dev/null +++ b/doc/tests/IMUDatabaseWriter.md @@ -0,0 +1,18 @@ +# IMU Database Writer Unit Tests + +Unit tests for `IMUDatabaseWriter` are implemented in `src/g2_2025_imu_reader_pkg/test/IMUDatabaseWriter.test.cpp` using Google Test and ROS2 test utilities. These tests validate that the node subscribes to the `imu_data` topic, receives IMU messages, and forwards parsed values to the `DatabaseManager` interface. Tests use dependency injection with a mock `DatabaseManager` to avoid requiring a real database connection. + +## Test Cases + +### 1. ConstructorTest + +**Description:** Verifies that `IMUDatabaseWriter` can be constructed. + +- **Test Action:** Create `IMUDatabaseWriter` node with a `MockDatabaseManager` +- **Expected Result:** Node instance created successfully without exceptions + +### 2. ReceivesAndForwardsIMU + +**Description:** Tests that the node receives IMU messages on the `imu_data` topic and calls `store_imu_data(...)` on the injected database manager. + +- **Expected Result:** Mock's `called_` flag is set to `true`, confirming the node forwarded the IMU data to the database manager