use crate::config::{LATENCY_OK_THRESHOLD_MS, LATENCY_SLOW_THRESHOLD_MS};
use crate::monitor::ConnectionStatus;
#[allow(dead_code)]
pub fn determine_status(avg_latency_ms: f64) -> ConnectionStatus {
if avg_latency_ms > LATENCY_SLOW_THRESHOLD_MS {
ConnectionStatus::Disconnected
} else if avg_latency_ms >= LATENCY_OK_THRESHOLD_MS {
ConnectionStatus::Slow
} else {
ConnectionStatus::Ok
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_status_ok_all_good() {
let status = determine_status(50.0);
assert_eq!(status, ConnectionStatus::Ok);
}
#[test]
fn test_status_ok_at_boundaries() {
let status = determine_status(99.0);
assert_eq!(status, ConnectionStatus::Ok);
}
#[test]
fn test_status_slow_latency() {
let status = determine_status(150.0);
assert_eq!(status, ConnectionStatus::Slow);
}
#[test]
fn test_status_slow_at_ok_threshold() {
let status = determine_status(100.0);
assert_eq!(status, ConnectionStatus::Slow);
}
#[test]
fn test_status_disconnected_latency() {
let status = determine_status(400.0);
assert_eq!(status, ConnectionStatus::Disconnected);
}
#[test]
fn test_status_slow_at_slow_threshold() {
let status = determine_status(300.0);
assert_eq!(status, ConnectionStatus::Slow);
}
#[test]
fn test_status_disconnected_all_bad() {
let status = determine_status(500.0);
assert_eq!(status, ConnectionStatus::Disconnected);
}
}