Spaces:
Sleeping
Sleeping
| use super::Weekday; | |
| use chrono::NaiveTime; | |
| use serde::{Deserialize, Serialize}; | |
| use solverforge::prelude::*; | |
| /// A candidate teaching period that the solver can assign to a lesson. | |
| pub struct Timeslot { | |
| pub id: String, | |
| pub index: usize, // the solver-facing join key | |
| pub day_of_week: Weekday, | |
| pub start_time: NaiveTime, | |
| pub end_time: NaiveTime, | |
| } | |
| impl Timeslot { | |
| pub fn new( | |
| index: usize, | |
| day_of_week: Weekday, | |
| start_time: NaiveTime, | |
| end_time: NaiveTime, | |
| ) -> Self { | |
| Self { | |
| id: format!("timeslot-{index}"), | |
| index, | |
| day_of_week, | |
| start_time, | |
| end_time, | |
| } | |
| } | |
| } | |
| mod tests { | |
| use super::*; | |
| fn test_timeslot_construction() { | |
| let fact = Timeslot::new(0, Weekday::Mon, Default::default(), Default::default()); | |
| assert_eq!(fact.index, 0); | |
| assert_eq!(fact.id, "timeslot-0"); | |
| let _ = &fact.day_of_week; | |
| let _ = &fact.start_time; | |
| let _ = &fact.end_time; | |
| } | |
| } | |