use super::*;
use rust_decimal_macros::dec;

#[test]
fn sqrt_known_values() {
    assert!((decimal_sqrt(dec!(4)) - dec!(2)).abs() < dec!(0.0001));
    assert!((decimal_sqrt(dec!(9)) - dec!(3)).abs() < dec!(0.0001));
    assert!((decimal_sqrt(dec!(2)) - dec!(1.4142)).abs() < dec!(0.001));
}

#[test]
fn sqrt_zero_and_negative() {
    assert_eq!(decimal_sqrt(dec!(0)), dec!(0));
    assert_eq!(decimal_sqrt(dec!(-1)), dec!(0));
}

#[test]
fn mean_calculation() {
    let values = vec![dec!(1), dec!(2), dec!(3), dec!(4), dec!(5)];
    assert_eq!(mean(&values), dec!(3));
}

#[test]
fn mean_empty() {
    let values: Vec<Decimal> = vec![];
    assert_eq!(mean(&values), dec!(0));
}

#[test]
fn std_deviation_known_values() {
    // Values: 2, 4, 4, 4, 5, 5, 7, 9
    // Mean = 5, Sample Variance ≈ 4.57, Sample StdDev ≈ 2.14
    let values = vec![
        dec!(2),
        dec!(4),
        dec!(4),
        dec!(4),
        dec!(5),
        dec!(5),
        dec!(7),
        dec!(9),
    ];
    let std = std_deviation(&values);
    assert!((std - dec!(2.14)).abs() < dec!(0.1));
}

#[test]
fn std_deviation_insufficient_data() {
    assert_eq!(std_deviation(&[dec!(5)]), dec!(0));
    assert_eq!(std_deviation(&[]), dec!(0));
}
