pub fn check_threshold(
context_tokens: u32,
context_window: u32,
threshold_percentage: Option<f32>,
) -> bool {
let threshold_pct = threshold_percentage.unwrap_or(0.8);
let threshold = (context_window as f32 * threshold_pct) as u32;
context_tokens >= threshold
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_check_threshold_below() {
assert!(!check_threshold(50, 1000, None));
}
#[test]
fn test_check_threshold_above() {
assert!(check_threshold(900, 1000, None));
}
#[test]
fn test_check_threshold_at_boundary() {
assert!(check_threshold(800, 1000, None));
}
#[test]
fn test_check_threshold_custom_percentage() {
assert!(check_threshold(60, 100, Some(0.5)));
assert!(!check_threshold(40, 100, Some(0.5)));
}
}