v0.11.1
This commit is contained in:
1 parent
db6d2f09db
commit
563523d2e2
18 files changed
+420
-62
No files matched your search
@@ -115,6 +115,37 @@ mod tests {
|
||||
assert!(!flow_timed_gate_update(&mut state, true, 30, start + chrono::Duration::seconds(32)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flow_state_duration_respects_minimum_maximum_and_reset() {
|
||||
let mut state = crate::models::FlowRuntimeNodeState::default();
|
||||
let start = Utc.with_ymd_and_hms(2026, 9, 2, 12, 0, 0).unwrap();
|
||||
assert_eq!(flow_state_duration_update(&mut state, true, 10, Some(30), start), (false, 0));
|
||||
assert_eq!(flow_state_duration_update(&mut state, true, 10, Some(30), start + chrono::Duration::seconds(10)), (true, 10));
|
||||
assert_eq!(flow_state_duration_update(&mut state, true, 10, Some(30), start + chrono::Duration::seconds(30)), (true, 30));
|
||||
assert_eq!(flow_state_duration_update(&mut state, true, 10, Some(30), start + chrono::Duration::seconds(31)), (false, 31));
|
||||
assert_eq!(flow_state_duration_update(&mut state, false, 10, Some(30), start + chrono::Duration::seconds(32)), (false, 0));
|
||||
assert!(state.since.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flow_change_gate_ignores_first_observation_and_detects_later_change() {
|
||||
let mut state = crate::models::FlowRuntimeNodeState::default();
|
||||
assert!(!flow_change_gate_update(&mut state, json!("off")));
|
||||
assert!(!flow_change_gate_update(&mut state, json!("off")));
|
||||
assert!(flow_change_gate_update(&mut state, json!("on")));
|
||||
assert!(!flow_change_gate_update(&mut state, json!("on")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flow_rate_limit_prunes_rolling_window_and_blocks_at_limit() {
|
||||
let mut state = crate::models::FlowRuntimeNodeState::default();
|
||||
let start = Utc.with_ymd_and_hms(2026, 9, 2, 12, 0, 0).unwrap();
|
||||
state.samples.push(crate::models::FlowRuntimeSample { at: start, value: 1.0 });
|
||||
state.samples.push(crate::models::FlowRuntimeSample { at: start + chrono::Duration::seconds(10), value: 1.0 });
|
||||
assert_eq!(flow_rate_limit_status(&mut state, 2, 60, start + chrono::Duration::seconds(20)), (false, 2));
|
||||
assert_eq!(flow_rate_limit_status(&mut state, 2, 60, start + chrono::Duration::seconds(61)), (true, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flow_rolling_statistics_compute_mean_median_and_prune_window() {
|
||||
let mut state = crate::models::FlowRuntimeNodeState::default();
|
||||
|
||||
Reference in new issue
Block a user