|
| 1 | +#include "gtest/gtest.h" |
| 2 | +#include "jres_solver/jres_solver.hpp" |
| 3 | +#include <string> |
| 4 | + |
| 5 | +namespace { |
| 6 | + |
| 7 | + const char* DUPLICATE_NAMES_JSON = R"({ |
| 8 | + "teamMembers": [ |
| 9 | + { "name": "DriverA", "isDriver": true }, |
| 10 | + { "name": "DriverA", "isDriver": true } |
| 11 | + ], |
| 12 | + "availability": {}, |
| 13 | + "stints": [ { "id": 1, "startTime": "2024-01-01T12:00:00.000Z", "endTime": "2024-01-01T13:00:00.000Z" } ] |
| 14 | + })"; |
| 15 | + |
| 16 | + TEST(ValidationTest, DuplicateNames) { |
| 17 | + JresSolverOptions options = {}; |
| 18 | + options.spotterMode = JRES_SPOTTER_MODE_NONE; |
| 19 | + |
| 20 | + JresSolverInput* input = jres_input_from_json(DUPLICATE_NAMES_JSON); |
| 21 | + ASSERT_NE(input, nullptr); |
| 22 | + |
| 23 | + JresSolverOutput* output = solve_race_schedule(input, &options); |
| 24 | + ASSERT_NE(output, nullptr); |
| 25 | + |
| 26 | + // Expect diagnosis |
| 27 | + ASSERT_GT(output->diagnosis_len, 0); |
| 28 | + bool foundDuplicateMsg = false; |
| 29 | + for (int i = 0; i < output->diagnosis_len; ++i) { |
| 30 | + std::string msg = output->diagnosis[i]; |
| 31 | + if (msg.find("Duplicate team member name") != std::string::npos) { |
| 32 | + foundDuplicateMsg = true; |
| 33 | + break; |
| 34 | + } |
| 35 | + } |
| 36 | + EXPECT_TRUE(foundDuplicateMsg) << "Should diagnose duplicate names"; |
| 37 | + |
| 38 | + free_jres_solver_input(input); |
| 39 | + free_jres_solver_output(output); |
| 40 | + } |
| 41 | + |
| 42 | + const char* NO_SPOTTERS_SEQUENTIAL_JSON = R"({ |
| 43 | + "teamMembers": [ |
| 44 | + { "name": "DriverA", "isDriver": true, "isSpotter": false }, |
| 45 | + { "name": "SpotterA", "isDriver": false, "isSpotter": false } |
| 46 | + ], |
| 47 | + "availability": {}, |
| 48 | + "stints": [ { "id": 1, "startTime": "2024-01-01T12:00:00.000Z", "endTime": "2024-01-01T13:00:00.000Z" } ] |
| 49 | + })"; |
| 50 | + |
| 51 | + TEST(ValidationTest, UnassignedSpotterSequential) { |
| 52 | + JresSolverOptions options = {}; |
| 53 | + options.spotterMode = JRES_SPOTTER_MODE_SEQUENTIAL; |
| 54 | + options.allowNoSpotter = false; |
| 55 | + |
| 56 | + JresSolverInput* input = jres_input_from_json(NO_SPOTTERS_SEQUENTIAL_JSON); |
| 57 | + ASSERT_NE(input, nullptr); |
| 58 | + |
| 59 | + JresSolverOutput* output = solve_race_schedule(input, &options); |
| 60 | + ASSERT_NE(output, nullptr); |
| 61 | + |
| 62 | + // Expect diagnosis about unassigned spotter |
| 63 | + ASSERT_GT(output->diagnosis_len, 0); |
| 64 | + bool foundSpecificMsg = false; |
| 65 | + for (int i = 0; i < output->diagnosis_len; ++i) { |
| 66 | + std::string msg = output->diagnosis[i]; |
| 67 | + if (msg.find("Stint 0") != std::string::npos && msg.find("has no assigned spotter") != std::string::npos) { |
| 68 | + foundSpecificMsg = true; |
| 69 | + break; |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + EXPECT_TRUE(foundSpecificMsg) << "Should diagnose specific unassigned stint for spotter"; |
| 74 | + |
| 75 | + free_jres_solver_input(input); |
| 76 | + free_jres_solver_output(output); |
| 77 | + } |
| 78 | +} |
0 commit comments