1#[derive(Debug, Clone, Copy, PartialEq)]
14pub struct DwellParams {
15 pub min_dwell: f64,
17 pub per_alighter: f64,
19 pub per_boarder: f64,
21}
22
23impl Default for DwellParams {
24 fn default() -> Self {
25 Self {
26 min_dwell: 8.0,
27 per_alighter: 1.8,
28 per_boarder: 2.6,
29 }
30 }
31}
32
33#[derive(Debug, Clone, Copy, PartialEq)]
35pub struct DwellTime {
36 pub total: f64,
38 pub from_alighters: f64,
40 pub from_boarders: f64,
42}
43
44pub fn compute(alighters: u32, boarders: u32, params: &DwellParams) -> DwellTime {
46 let a = params.per_alighter * alighters as f64;
47 let b = params.per_boarder * boarders as f64;
48 DwellTime {
49 total: params.min_dwell + a + b,
50 from_alighters: a,
51 from_boarders: b,
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn default_params_match_tcqsm_range() {
61 let d = compute(5, 10, &DwellParams::default());
62 assert!((d.total - (8.0 + 5.0 * 1.8 + 10.0 * 2.6)).abs() < 1e-9);
63 }
64
65 #[test]
66 fn zero_passengers_gives_min_dwell() {
67 let d = compute(0, 0, &DwellParams::default());
68 assert_eq!(d.total, 8.0);
69 }
70}