Spaces:
Sleeping
Sleeping
File size: 988 Bytes
4b94493 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | use serde::{Deserialize, Serialize};
use solverforge::prelude::*;
/// A teacher with a weekly availability calendar.
#[problem_fact]
#[derive(Serialize, Deserialize)]
pub struct Teacher {
#[planning_id]
pub id: String,
#[serde(skip)]
pub index: usize, // the solver-facing join key
pub name: String,
pub availability: Vec<bool>,
}
impl Teacher {
pub fn new(index: usize, name: impl Into<String>, availability: impl Into<Vec<bool>>) -> Self {
Self {
id: format!("teacher-{index}"),
index,
name: name.into(),
availability: availability.into(),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_teacher_construction() {
let fact = Teacher::new(0, "test", vec![true; 40]);
assert_eq!(fact.index, 0);
assert_eq!(fact.id, "teacher-0");
assert_eq!(fact.name, "test");
let _ = &fact.name;
let _ = &fact.availability;
}
}
|