Change ResidentId(String) to ResidentId(u8), impl Copy for ShiftType, use u8 for all UserConfig params

This commit is contained in:
2026-01-17 19:27:35 +02:00
parent 5bad63e8a7
commit 125ddc3117
8 changed files with 161 additions and 192 deletions

View File

@@ -13,10 +13,10 @@ mod integration_tests {
#[fixture]
fn minimal_config() -> UserConfig {
UserConfig::new(2).with_residents(vec![
Resident::new("1", "R1"),
Resident::new("2", "R2"),
Resident::new("3", "R3"),
Resident::new("4", "R4"),
Resident::new(1, "R1"),
Resident::new(2, "R2"),
Resident::new(3, "R3"),
Resident::new(4, "R4"),
])
}
@@ -25,41 +25,41 @@ mod integration_tests {
UserConfig::new(2)
.with_holidays(vec![2, 3, 10, 11, 12, 25])
.with_residents(vec![
Resident::new("1", "R1").with_max_shifts(3),
Resident::new("2", "R2").with_max_shifts(4),
Resident::new("3", "R3").with_reduced_load(),
Resident::new("4", "R4").with_allowed_types(vec![ShiftType::Closed]),
Resident::new("5", "R5")
Resident::new(1, "R1").with_max_shifts(3),
Resident::new(2, "R2").with_max_shifts(4),
Resident::new(3, "R3").with_reduced_load(),
Resident::new(4, "R4").with_allowed_types(vec![ShiftType::Closed]),
Resident::new(5, "R5")
.with_allowed_types(vec![ShiftType::OpenFirst, ShiftType::OpenSecond]),
Resident::new("6", "R6").with_negative_shifts(vec![Day(5), Day(15), Day(25)]),
Resident::new("7", "R7"),
Resident::new("8", "R8"),
Resident::new("9", "R9"),
Resident::new("10", "R10"),
Resident::new(6, "R6").with_negative_shifts(vec![Day(5), Day(15), Day(25)]),
Resident::new(7, "R7"),
Resident::new(8, "R8"),
Resident::new(9, "R9"),
Resident::new(10, "R10"),
])
.with_toxic_pairs(vec![
ToxicPair::new("1", "2"),
ToxicPair::new("3", "4"),
ToxicPair::new("7", "8"),
ToxicPair::new(1, 2),
ToxicPair::new(3, 4),
ToxicPair::new(7, 8),
])
}
#[fixture]
fn manual_shifts_heavy_config() -> UserConfig {
UserConfig::new(2).with_residents(vec![
Resident::new("1", "R1").with_manual_shifts(vec![
Resident::new(1, "R1").with_manual_shifts(vec![
Slot::new(Day(1), ShiftPosition::First),
Slot::new(Day(3), ShiftPosition::First),
Slot::new(Day(5), ShiftPosition::Second),
]),
Resident::new("2", "R2").with_manual_shifts(vec![
Resident::new(2, "R2").with_manual_shifts(vec![
Slot::new(Day(2), ShiftPosition::First),
Slot::new(Day(4), ShiftPosition::First),
]),
Resident::new("3", "R3"),
Resident::new("4", "R4"),
Resident::new("5", "R5"),
Resident::new("6", "R6"),
Resident::new(3, "R3"),
Resident::new(4, "R4"),
Resident::new(5, "R5"),
Resident::new(6, "R6"),
])
}
@@ -68,27 +68,27 @@ mod integration_tests {
UserConfig::new(2)
.with_holidays(vec![5, 12, 19, 26])
.with_residents(vec![
Resident::new("1", "R1")
Resident::new(1, "R1")
.with_max_shifts(3)
.with_negative_shifts(vec![Day(1), Day(2), Day(3)]),
Resident::new("2", "R2")
Resident::new(2, "R2")
.with_max_shifts(3)
.with_negative_shifts(vec![Day(4), Day(5), Day(6)]),
Resident::new("3", "R3")
Resident::new(3, "R3")
.with_max_shifts(3)
.with_negative_shifts(vec![Day(7), Day(8), Day(9)]),
Resident::new("4", "R4").with_allowed_types(vec![ShiftType::Closed]),
Resident::new("5", "R5")
Resident::new(4, "R4").with_allowed_types(vec![ShiftType::Closed]),
Resident::new(5, "R5")
.with_allowed_types(vec![ShiftType::OpenFirst, ShiftType::OpenSecond]),
Resident::new("6", "R6"),
Resident::new("7", "R7"),
Resident::new("8", "R8"),
Resident::new(6, "R6"),
Resident::new(7, "R7"),
Resident::new(8, "R8"),
])
.with_toxic_pairs(vec![
ToxicPair::new("1", "2"),
ToxicPair::new("2", "3"),
ToxicPair::new("5", "6"),
ToxicPair::new("6", "7"),
ToxicPair::new(1, 2),
ToxicPair::new(2, 3),
ToxicPair::new(5, 6),
ToxicPair::new(6, 7),
])
}
@@ -160,7 +160,7 @@ mod integration_tests {
let r2 = schedule.get_resident_id(&Slot::new(day, ShiftPosition::Second));
assert_ne!(r1, r2);
if let (Some(id1), Some(id2)) = (r1, r2) {
let pair = ToxicPair::from((id1.clone(), id2.clone()));
let pair = ToxicPair::from((*id1, *id2));
assert!(config.toxic_pairs.iter().all(|t| !t.matches(&pair)));
}
}