UPDATE: Adds 56 functions in the Statistical section

Uses statrs for numerical functions

REFACTOR: Put statistical functions on its own module

This might seem counter-intuitive but the wasm build after this refactor
is 1528 bytes smaller :)
This commit is contained in:
Nicolás Hatcher
2025-11-20 21:10:47 +01:00
committed by Nicolás Hatcher Andrés
parent 67ef3bcf87
commit 6822505602
54 changed files with 7290 additions and 387 deletions

View File

@@ -0,0 +1,41 @@
#![allow(clippy::unwrap_used)]
use crate::test::util::new_empty_model;
#[test]
fn test_fn_poisson_dist_smoke() {
let mut model = new_empty_model();
// λ = 2, x = 3
// P(X = 3) ≈ 0.180447045
// P(X <= 3) ≈ 0.857123461
model._set("A1", "=POISSON.DIST(3, 2, FALSE)");
model._set("A2", "=POISSON.DIST(3, 2, TRUE)");
// Wrong arg count
model._set("A3", "=POISSON.DIST(3, 2)");
model._set("A4", "=POISSON.DIST(3, 2, TRUE, FALSE)");
// Domain errors
model._set("A5", "=POISSON.DIST(-1, 2, TRUE)"); // x < 0
model._set("A6", "=POISSON.DIST(3, -2, TRUE)"); // mean < 0
// λ = 0 special cases
model._set("A7", "=POISSON.DIST(0, 0, FALSE)"); // 1
model._set("A8", "=POISSON.DIST(1, 0, FALSE)"); // 0
model._set("A9", "=POISSON.DIST(5, 0, TRUE)"); // 1
model.evaluate();
assert_eq!(model._get_text("A1"), *"0.180447044");
assert_eq!(model._get_text("A2"), *"0.85712346");
assert_eq!(model._get_text("A3"), *"#ERROR!");
assert_eq!(model._get_text("A4"), *"#ERROR!");
assert_eq!(model._get_text("A5"), *"#NUM!");
assert_eq!(model._get_text("A6"), *"#NUM!");
assert_eq!(model._get_text("A7"), *"1");
assert_eq!(model._get_text("A8"), *"0");
assert_eq!(model._get_text("A9"), *"1");
}