Expand integration suite to cover all months of 2026, minor refactorings
This commit is contained in:
@@ -104,6 +104,18 @@ impl UserConfig {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn update_month(&mut self, month: u8) {
|
||||
self.month = Month::try_from(month).unwrap();
|
||||
|
||||
self.total_days = self.month.num_days(self.year).unwrap();
|
||||
|
||||
self.total_slots = (1..=self.total_days)
|
||||
.map(|d| if Day(d).is_open_shift() { 2 } else { 1 })
|
||||
.sum();
|
||||
|
||||
self.total_holiday_slots = self.total_holiday_slots()
|
||||
}
|
||||
|
||||
fn total_holiday_slots(&self) -> u8 {
|
||||
(1..=self.total_days)
|
||||
.filter(|&d| self.is_holiday_or_weekend(Day(d)))
|
||||
@@ -212,7 +224,7 @@ impl TryFrom<UserConfigDTO> for UserConfig {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{
|
||||
config::UserConfig,
|
||||
config::{ToxicPair, UserConfig},
|
||||
fixtures::complex_config,
|
||||
schedule::ShiftType,
|
||||
slot::{Day, ShiftPosition, Slot},
|
||||
@@ -248,4 +260,18 @@ mod tests {
|
||||
assert!(complex_config.is_holiday_or_weekend_slot(sun));
|
||||
assert!(complex_config.is_holiday_or_weekend_slot(manual_holiday));
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
fn test_toxic_pair_matches() {
|
||||
let pair_1 = ToxicPair::new(1, 2);
|
||||
let pair_1_r = ToxicPair::new(2, 1);
|
||||
let pair_2 = ToxicPair::new(3, 1);
|
||||
|
||||
assert!(pair_1.matches(&pair_1_r));
|
||||
assert!(pair_1_r.matches(&pair_1));
|
||||
assert!(!pair_1.matches(&pair_2));
|
||||
assert!(!pair_2.matches(&pair_1));
|
||||
assert!(!pair_1_r.matches(&pair_2));
|
||||
assert!(!pair_2.matches(&pair_1_r));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user