use super::*;
#[test]
fn percentile_empty_slice_is_zero() {
assert_eq!(percentile(&[], 0.99), 0);
}
#[test]
fn percentile_single_element() {
assert_eq!(percentile(&[42], 0.99), 42);
}
#[test]
fn percentile_p99_of_100_samples_is_element_98() {
let sorted: Vec<u64> = (0..100).collect();
assert_eq!(percentile(&sorted, 0.99), 98);
}
#[test]
fn percentile_p99_of_1000_samples_is_element_989() {
let sorted: Vec<u64> = (0..1000).collect();
assert_eq!(percentile(&sorted, 0.99), 989);
}
#[test]
fn percentile_saturates_into_bounds_for_small_n() {
for n in 1u64..=10 {
let sorted: Vec<u64> = (0..n).collect();
let v = percentile(&sorted, 0.99);
assert!(v < n, "percentile({sorted:?}, 0.99)={v} must be < n ({n})");
}
}
#[test]
fn percentile_p50_on_odd_count_is_middle() {
let sorted: Vec<u64> = (0..9).collect();
assert_eq!(percentile(&sorted, 0.50), 4);
}
#[test]
#[cfg(debug_assertions)]
#[should_panic(expected = "percentile() requires sorted input")]
fn percentile_unsorted_input_panics_in_debug() {
let unsorted: Vec<u64> = vec![5, 1, 3];
let _ = percentile(&unsorted, 0.99);
}
#[test]
fn percentile_equal_consecutive_values_do_not_panic() {
let with_dups: Vec<u64> = vec![1, 1, 1, 2, 2, 3];
let _ = percentile(&with_dups, 0.99);
}