Reorganize integration tests, simplify fn signatures

This commit is contained in:
2026-02-22 13:01:28 +02:00
parent a41d1cd469
commit 76d308351a
8 changed files with 270 additions and 344 deletions

View File

@@ -131,7 +131,7 @@ impl Scheduler {
let mut valid_resident_ids = self.valid_residents(slot, schedule, tracker);
valid_resident_ids.shuffle(&mut rng);
valid_resident_ids.sort_by_key(|res_id| {
let type_count = tracker.get_type_count(res_id, slot.shift_type());
let type_count = tracker.current_shift_type_workload(res_id, slot.shift_type());
let workload = tracker.current_workload(res_id);
(type_count, workload)
});
@@ -162,7 +162,7 @@ impl Scheduler {
schedule: &MonthlySchedule,
tracker: &WorkloadTracker,
) -> Vec<ResidentId> {
let is_holiday_slot = self.config.is_holiday_or_weekend_slot(slot.day.0);
let is_holiday_slot = self.config.is_holiday_or_weekend_slot(slot);
let other_resident_id = slot
.other_position()
.and_then(|partner_slot| schedule.get_resident_id(&partner_slot));
@@ -190,65 +190,9 @@ impl Scheduler {
&& r.allowed_types.contains(&slot.shift_type())
&& !tracker.reached_workload_limit(&self.bounds, &r.id)
&& (!is_holiday_slot || !tracker.reached_holiday_limit(&self.bounds, &r.id))
&& !tracker.reached_shift_type_limit(&self.bounds, &r.id, &slot)
&& !tracker.reached_shift_type_limit(&self.bounds, &r.id, slot.shift_type())
})
.map(|r| r.id)
.collect()
}
}
#[cfg(test)]
mod tests {
use rstest::{fixture, rstest};
use crate::{
config::UserConfig,
resident::Resident,
schedule::MonthlySchedule,
scheduler::Scheduler,
workload::{WorkloadBounds, WorkloadTracker},
};
#[fixture]
fn schedule() -> MonthlySchedule {
MonthlySchedule::new()
}
#[fixture]
fn config() -> UserConfig {
UserConfig::default().with_residents(vec![
Resident::new(1, "R1"),
Resident::new(2, "R2"),
Resident::new(3, "R3"),
Resident::new(4, "R4"),
Resident::new(5, "R5"),
Resident::new(6, "R6"),
])
}
#[fixture]
fn bounds(config: UserConfig) -> WorkloadBounds {
WorkloadBounds::new_with_config(&config)
}
#[fixture]
fn scheduler(config: UserConfig, bounds: WorkloadBounds) -> Scheduler {
Scheduler::new(config, bounds)
}
#[fixture]
fn tracker() -> WorkloadTracker {
WorkloadTracker::default()
}
#[rstest]
fn test_search(
mut schedule: MonthlySchedule,
mut tracker: WorkloadTracker,
scheduler: Scheduler,
) {
let solved = scheduler.run(&mut schedule, &mut tracker);
assert!(solved.is_ok());
assert!(solved.unwrap());
}
}