Remove min by shift type boundaries, improve logging, add more tests, add logs in tests, move fixtures in separate file, move restrictions_violated logic into valid_residents of next slot

This commit is contained in:
2026-02-21 23:46:26 +02:00
parent c291328bfa
commit a41d1cd469
15 changed files with 856 additions and 453 deletions

View File

@@ -1,13 +1,16 @@
use std::collections::HashMap;
use anyhow::Context;
use chrono::Month;
use serde::{Deserialize, Serialize};
use crate::{
resident::{Resident, ResidentDTO, ResidentId},
schedule::ShiftType,
slot::Day,
};
const MONTH: u8 = 2;
const MONTH: u8 = 4;
const YEAR: i32 = 2026;
#[derive(Debug, Clone)]
@@ -87,6 +90,21 @@ impl UserConfig {
day.is_weekend(self.month.number_from_month(), self.year)
|| self.holidays.contains(&(day.0))
}
pub fn get_initial_supply(&self) -> HashMap<ShiftType, u8> {
let mut supply = HashMap::new();
let total_days = self.total_days;
for d in 1..=total_days {
if Day(d).is_open_shift() {
*supply.entry(ShiftType::OpenFirst).or_insert(0) += 1;
*supply.entry(ShiftType::OpenSecond).or_insert(0) += 1;
} else {
*supply.entry(ShiftType::Closed).or_insert(0) += 1;
}
}
supply
}
}
impl Default for UserConfig {
@@ -153,3 +171,18 @@ impl TryFrom<UserConfigDTO> for UserConfig {
})
}
}
#[cfg(test)]
mod tests {
use crate::{config::UserConfig, fixtures::complex_config, schedule::ShiftType};
use rstest::rstest;
#[rstest]
fn test_get_initial_supply(complex_config: UserConfig) {
let supply = complex_config.get_initial_supply();
assert_eq!(15, *supply.get(&ShiftType::OpenFirst).unwrap());
assert_eq!(15, *supply.get(&ShiftType::OpenSecond).unwrap());
assert_eq!(15, *supply.get(&ShiftType::Closed).unwrap());
}
}