Use maps to track workload progress instead of recalculating them at every step of the search, calculate total days/slots once, add integration tests, add log folder

This commit is contained in:
2026-01-17 18:41:43 +02:00
parent 908f114e54
commit 5bad63e8a7
10 changed files with 819 additions and 574 deletions

View File

@@ -79,16 +79,20 @@ impl Slot {
self.day.greater_than(&Day(limit))
}
pub fn other_position(&self) -> Self {
pub fn other_position(&self) -> Option<Self> {
if !self.day.is_open_shift() {
return None;
}
let other_pos = match self.position {
ShiftPosition::First => ShiftPosition::Second,
ShiftPosition::Second => ShiftPosition::First,
};
Self {
Some(Self {
day: self.day,
position: other_pos,
}
})
}
pub fn shift_type(&self) -> ShiftType {
@@ -186,7 +190,10 @@ pub fn month_to_greek(month: u32) -> &'static str {
mod tests {
use rstest::rstest;
use crate::slot::{Day, ShiftPosition, Slot};
use crate::{
schedule::ShiftType,
slot::{Day, ShiftPosition, Slot},
};
#[rstest]
fn test_slot() {
@@ -215,6 +222,14 @@ mod tests {
assert!(!slot_1.greater_than(1));
assert!(!slot_2.greater_than(1));
assert!(slot_3.greater_than(1));
assert_eq!(slot_1.other_position(), Some(slot_1.next()));
assert_eq!(slot_2.other_position(), Some(slot_2.previous()));
assert_eq!(slot_3.other_position(), None);
assert_eq!(slot_1.shift_type(), ShiftType::OpenFirst);
assert_eq!(slot_2.shift_type(), ShiftType::OpenSecond);
assert_eq!(slot_3.shift_type(), ShiftType::Closed);
}
#[rstest]