use culors::normalize_positions;
#[test]
fn all_missing_spread_evenly() {
let mut stops = [f64::NAN; 5];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0, 0.25, 0.5, 0.75, 1.0]);
}
#[test]
fn partial_endpoints_anchor_fill() {
let mut stops = [0.2, f64::NAN, f64::NAN, 0.8];
normalize_positions(&mut stops);
assert_eq!(stops, [0.2, 0.4, 0.600_000_000_000_000_1, 0.8]);
}
#[test]
fn missing_first_anchors_to_zero() {
let mut stops = [f64::NAN, f64::NAN, 0.8];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0, 0.4, 0.8]);
}
#[test]
fn missing_last_anchors_to_one() {
let mut stops = [0.5, f64::NAN, f64::NAN];
normalize_positions(&mut stops);
assert_eq!(stops, [0.5, 0.75, 1.0]);
}
#[test]
fn three_missing_anchored() {
let mut stops = [f64::NAN, f64::NAN, f64::NAN];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0, 0.5, 1.0]);
}
#[test]
fn two_missing_become_zero_one() {
let mut stops = [f64::NAN, f64::NAN];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0, 1.0]);
}
#[test]
fn nested_gaps_fill_against_local_neighbours() {
let mut stops = [0.0, f64::NAN, 0.4, f64::NAN, f64::NAN, 1.0];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]);
}
#[test]
fn gap_fill_outside_unit_range_is_preserved() {
let mut stops = [-0.5, f64::NAN, f64::NAN, 1.5];
normalize_positions(&mut stops);
assert_eq!(stops[0], -0.5);
assert_eq!(stops[3], 1.5);
let expected_mid_lo = -0.5 + (1.5 - -0.5) / 3.0; let expected_mid_hi = -0.5 + 2.0 * (1.5 - -0.5) / 3.0; assert!((stops[1] - expected_mid_lo).abs() < 1e-12);
assert!((stops[2] - expected_mid_hi).abs() < 1e-12);
}
#[test]
fn out_of_order_position_clamps_forward() {
let mut stops = [0.5, 0.3, 0.8];
normalize_positions(&mut stops);
assert_eq!(stops, [0.5, 0.5, 0.8]);
}
#[test]
fn long_decreasing_run_clamps_to_max_so_far() {
let mut stops = [0.5, 0.3, 0.4, 0.2, 0.6];
normalize_positions(&mut stops);
assert_eq!(stops, [0.5, 0.5, 0.5, 0.5, 0.6]);
}
#[test]
fn fully_defined_monotone_input_unchanged() {
let mut stops = [0.0, 0.5, 1.0];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0, 0.5, 1.0]);
}
#[test]
fn empty_slice_is_noop() {
let mut stops: [f64; 0] = [];
normalize_positions(&mut stops);
assert_eq!(stops.len(), 0);
}
#[test]
fn single_missing_anchors_to_zero() {
let mut stops = [f64::NAN];
normalize_positions(&mut stops);
assert_eq!(stops, [0.0]);
}
#[test]
fn single_defined_passes_through() {
let mut stops = [0.5];
normalize_positions(&mut stops);
assert_eq!(stops, [0.5]);
}
#[test]
fn returns_same_slice_for_chaining() {
let mut stops = [f64::NAN, f64::NAN];
let out = normalize_positions(&mut stops);
assert_eq!(out.as_ptr(), stops.as_ptr());
}