Add option to manually swap shifts after the schedule has been generated

This commit is contained in:
2026-07-02 19:15:07 +03:00
parent 515b9aa317
commit 9d8eacfb2b
7 changed files with 550 additions and 31 deletions

View File

@@ -126,6 +126,36 @@ mod integration_tests {
Ok(())
}
#[rstest]
fn test_swap_preserves_constraints(
#[values(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)] month_idx: u8,
mut minimal_config: UserConfig,
) -> anyhow::Result<()> {
minimal_config.update_month(month_idx);
let scheduler = Scheduler::new_with_config(minimal_config.clone());
let mut schedule = MonthlySchedule::new();
let mut tracker = WorkloadTracker::default();
assert!(scheduler.run(&mut schedule, &mut tracker)?);
let slots: Vec<_> = schedule.0.keys().copied().collect();
let mut swapped = false;
for slot in slots {
let candidates = schedule.possible_swaps(slot, &minimal_config);
if let Some(&(swap_target, _)) = candidates.first() {
schedule
.apply_swap(slot, swap_target, &minimal_config, &mut tracker)
.expect("apply_swap failed for a candidate returned by possible_swaps");
swapped = true;
break;
}
}
assert!(swapped, "No valid swap found in generated schedule");
validate_all_constraints(&schedule, &tracker, &minimal_config);
Ok(())
}
#[rstest]
fn test_export_pipeline(minimal_config: UserConfig) -> anyhow::Result<()> {
let scheduler = Scheduler::new_with_config(minimal_config.clone());