|
| 1 | +/** |
| 2 | + * @file test/test_availability_boundaries.cpp |
| 3 | + * @brief Tests for precise availability boundary conditions. |
| 4 | + */ |
| 5 | + |
| 6 | +#include "gtest/gtest.h" |
| 7 | +#include "jres_solver/jres_solver.hpp" |
| 8 | +#include "nlohmann/json.hpp" |
| 9 | +#include <vector> |
| 10 | +#include <string> |
| 11 | + |
| 12 | +using json = nlohmann::json; |
| 13 | + |
| 14 | +TEST(AvailabilityBoundaryTest, StintEndsExactlyAtUnavailableStart) { |
| 15 | + // Stint: 13:00 - 14:00. Unavailable at 14:00. Should be VALID. |
| 16 | + json j; |
| 17 | + j["success"] = true; |
| 18 | + j["consecutiveStints"] = 1; |
| 19 | + j["minimumRestHours"] = 0; |
| 20 | + j["teamMembers"] = {{{"name", "D"}, {"isDriver", true}, {"isSpotter", false}}}; |
| 21 | + j["stints"] = {{{"id", 1}, {"startTime", "2026-01-17T13:00:00.000Z"}, {"endTime", "2026-01-17T14:00:00.000Z"}}}; |
| 22 | + j["availability"] = {{"D", {{"2026-01-17T13:00:00.000Z", "Available"}, {"2026-01-17T14:00:00.000Z", "Unavailable"}}}}; |
| 23 | + j["firstStintDriver"] = nullptr; |
| 24 | + |
| 25 | + JresSolverInput* input = jres_input_from_json(j.dump().c_str()); |
| 26 | + JresSolverOptions options = {}; |
| 27 | + options.spotterMode = JRES_SPOTTER_MODE_NONE; |
| 28 | + options.allowNoSpotter = true; |
| 29 | + |
| 30 | + JresSolverOutput* output = solve_race_schedule(input, &options); |
| 31 | + bool hasViolation = false; |
| 32 | + for (int i = 0; i < output->diagnosis_len; ++i) { |
| 33 | + if (std::string(output->diagnosis[i]).find("Violation: Unavailable Driver") != std::string::npos) hasViolation = true; |
| 34 | + } |
| 35 | + |
| 36 | + EXPECT_FALSE(hasViolation); |
| 37 | + free_jres_solver_input(input); |
| 38 | + free_jres_solver_output(output); |
| 39 | +} |
| 40 | + |
| 41 | +TEST(AvailabilityBoundaryTest, StintOverlapsUnavailableByOneMinute) { |
| 42 | + // Stint: 13:00 - 14:01. Unavailable at 14:00. Should be INVALID. |
| 43 | + json j; |
| 44 | + j["success"] = true; |
| 45 | + j["consecutiveStints"] = 1; |
| 46 | + j["minimumRestHours"] = 0; |
| 47 | + j["teamMembers"] = {{{"name", "D"}, {"isDriver", true}, {"isSpotter", false}}}; |
| 48 | + j["stints"] = {{{"id", 1}, {"startTime", "2026-01-17T13:00:00.000Z"}, {"endTime", "2026-01-17T14:01:00.000Z"}}}; |
| 49 | + j["availability"] = {{"D", {{"2026-01-17T13:00:00.000Z", "Available"}, {"2026-01-17T14:00:00.000Z", "Unavailable"}}}}; |
| 50 | + j["firstStintDriver"] = nullptr; |
| 51 | + |
| 52 | + JresSolverInput* input = jres_input_from_json(j.dump().c_str()); |
| 53 | + JresSolverOptions options = {}; |
| 54 | + options.spotterMode = JRES_SPOTTER_MODE_NONE; |
| 55 | + options.allowNoSpotter = true; |
| 56 | + |
| 57 | + JresSolverOutput* output = solve_race_schedule(input, &options); |
| 58 | + bool hasViolation = false; |
| 59 | + for (int i = 0; i < output->diagnosis_len; ++i) { |
| 60 | + if (std::string(output->diagnosis[i]).find("Violation: Unavailable Driver") != std::string::npos) hasViolation = true; |
| 61 | + } |
| 62 | + |
| 63 | + EXPECT_TRUE(hasViolation); |
| 64 | + free_jres_solver_input(input); |
| 65 | + free_jres_solver_output(output); |
| 66 | +} |
0 commit comments