use gonidium::Value;

/// Assert that two slices of `Value` are element-wise equal, with a small
/// epsilon tolerance for floating-point values.
pub fn assert_values_close(lhs: &[Value], rhs: &[Value]) {
    fn as_f64(v: &Value) -> Option<f64> {
        match v {
            Value::F16(x) => Some(x.to_f64()),
            Value::BF16(x) => Some(x.to_f64()),
            Value::F32(x) => Some(*x as f64),
            Value::F64(x) => Some(*x),
            _ => None,
        }
    }

    assert_eq!(lhs.len(), rhs.len(), "output length mismatch");
    for (l, r) in lhs.iter().zip(rhs.iter()) {
        if let (Some(a), Some(b)) = (as_f64(l), as_f64(r)) {
            assert!((a - b).abs() <= 1e-12, "float mismatch: {a} vs {b}");
        } else {
            assert_eq!(l, r);
        }
    }
}
