use greeners::ProportionTests;
#[test]
fn test_1samp_ztest() {
let (z, pval) = ProportionTests::proportions_ztest_1samp(60, 100, 0.5).unwrap();
assert!((z - 2.0).abs() < 1e-10);
assert!((pval - 0.04550026).abs() < 1e-4);
}
#[test]
fn test_2samp_ztest() {
let (z, pval) = ProportionTests::proportions_ztest_2samp(45, 100, 55, 100).unwrap();
assert!((z - (-std::f64::consts::SQRT_2)).abs() < 1e-4);
assert!((pval - 0.1573).abs() < 1e-3);
}
#[test]
fn test_wilson_confint() {
let (lower, upper) = ProportionTests::proportion_confint(30, 100, 0.05).unwrap();
assert!(lower > 0.21 && lower < 0.23);
assert!(upper > 0.39 && upper < 0.40);
assert!(lower < upper);
}
#[test]
fn test_chi2_contingency() {
let table = [[10, 20], [30, 40]];
let (chi2, pval) = ProportionTests::chi2_contingency(&table).unwrap();
assert!((chi2 - 0.7937).abs() < 1e-3);
assert!((pval - 0.373).abs() < 0.01);
}
#[test]
fn test_1samp_errors() {
assert!(ProportionTests::proportions_ztest_1samp(0, 0, 0.5).is_err());
assert!(ProportionTests::proportions_ztest_1samp(101, 100, 0.5).is_err());
assert!(ProportionTests::proportions_ztest_1samp(50, 100, 0.0).is_err());
}