use approx::assert_relative_eq; use puruspe::{beta, betai, invbetai}; #[test] fn test_beta() { for &(a, b, expected) in BETA_TABLE.iter() { let result = beta(a, b); let abs_eps = f64::EPSILON; let rel_eps = 1e-10; assert_relative_eq!(result, expected, epsilon = abs_eps, max_relative = rel_eps); } } #[test] fn test_betai() { for &(a, b, x, expected) in BETAI_TABLE.iter() { let result = betai(a, b, x); let abs_eps = f64::EPSILON; let rel_eps = 1e-10; assert_relative_eq!(result, expected, epsilon = abs_eps, max_relative = rel_eps); } } #[test] fn test_invbetai() { for &(a, b, p, expected) in INVBETAI_TABLE.iter() { let result = invbetai(p, a, b); let abs_eps = f64::EPSILON; let rel_eps = 1e-9; assert_relative_eq!(result, expected, epsilon = abs_eps, max_relative = rel_eps); } } const BETA_TABLE: [(f64, f64, f64); 7] = [ ( 1.00000000000000e-01, 1.00000000000000e-01, 1.97146394890502e+01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 3.14159265358979e+00, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 1.00000000000000e+00, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 1.66666666666667e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 8.12698412698413e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 8.12698412698413e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 1.08250882244690e-06, ), ]; const BETAI_TABLE: [(f64, f64, f64, f64); 35] = [ ( 1.00000000000000e-01, 1.00000000000000e-01, 1.00000000000000e-01, 4.06385093936276e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 2.50000000000000e-01, 4.51957853676650e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 7.50000000000000e-01, 5.48042146323350e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 9.00000000000000e-01, 5.93614906063724e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 1.00000000000000e-01, 2.04832764699133e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 2.50000000000000e-01, 3.33333333333333e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 7.50000000000000e-01, 6.66666666666667e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 9.00000000000000e-01, 7.95167235300867e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 1.00000000000000e-01, 1.00000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 2.50000000000000e-01, 2.50000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 7.50000000000000e-01, 7.50000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 9.00000000000000e-01, 9.00000000000000e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 1.00000000000000e-01, 2.80000000000000e-02, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 2.50000000000000e-01, 1.56250000000000e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 7.50000000000000e-01, 8.43750000000000e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 9.00000000000000e-01, 9.72000000000000e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 1.00000000000000e-01, 6.83357084979988e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 2.50000000000000e-01, 9.02145385742188e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 5.00000000000000e-01, 9.89880440264566e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 7.50000000000000e-01, 9.99729704252745e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 9.00000000000000e-01, 9.99997429410301e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 1.00000000000000e-01, 2.57058969922937e-06, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 2.50000000000000e-01, 2.70295747254618e-04, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01, 1.01195597354337e-02, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 7.50000000000000e-01, 9.78546142578125e-02, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 9.00000000000000e-01, 3.16642915020012e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 1.00000000000000e-01, 3.92988232712800e-06, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 2.50000000000000e-01, 8.90327930392232e-03, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 7.50000000000000e-01, 9.91096720696078e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 9.00000000000000e-01, 9.99996070117673e-01, ), ]; const INVBETAI_TABLE: [(f64, f64, f64, f64); 49] = [ ( 1.00000000000000e-01, 1.00000000000000e-01, 1.00000000000000e-02, 8.86928065555021e-18, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 1.00000000000000e-01, 8.86928001193458e-08, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 2.50000000000000e-01, 8.45255532847130e-04, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 7.50000000000000e-01, 9.99154744467153e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 9.00000000000000e-01, 9.99999911307200e-01, ), ( 1.00000000000000e-01, 1.00000000000000e-01, 9.90000000000000e-01, 1.00000000000000e+00, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 1.00000000000000e-02, 2.46719817134221e-04, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 1.00000000000000e-01, 2.44717418524232e-02, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 2.50000000000000e-01, 1.46446609406726e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 7.50000000000000e-01, 8.53553390593274e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 9.00000000000000e-01, 9.75528258147577e-01, ), ( 5.00000000000000e-01, 5.00000000000000e-01, 9.90000000000000e-01, 9.99753280182866e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 1.00000000000000e-02, 1.00000000000000e-02, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 1.00000000000000e-01, 1.00000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 2.50000000000000e-01, 2.50000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 7.50000000000000e-01, 7.50000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 9.00000000000000e-01, 9.00000000000000e-01, ), ( 1.00000000000000e+00, 1.00000000000000e+00, 9.90000000000000e-01, 9.90000000000000e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 1.00000000000000e-02, 5.89031357781953e-02, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 1.00000000000000e-01, 1.95800105659092e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 2.50000000000000e-01, 3.26351822333070e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 7.50000000000000e-01, 6.73648177666930e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 9.00000000000000e-01, 8.04199894340908e-01, ), ( 2.00000000000000e+00, 2.00000000000000e+00, 9.90000000000000e-01, 9.41096864221805e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 1.00000000000000e-02, 1.65126948488293e-05, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 1.00000000000000e-01, 1.65851285512318e-03, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 2.50000000000000e-01, 1.06155428458617e-02, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 5.00000000000000e-01, 4.66872453369664e-02, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 7.50000000000000e-01, 1.29788914955044e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 9.00000000000000e-01, 2.47272226802556e-01, ), ( 5.00000000000000e-01, 5.00000000000000e+00, 9.90000000000000e-01, 5.01104785327943e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 1.00000000000000e-02, 4.98895214672057e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 1.00000000000000e-01, 7.52727773197444e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 2.50000000000000e-01, 8.70211085044956e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 5.00000000000000e-01, 9.53312754663034e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 7.50000000000000e-01, 9.89384457154138e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 9.00000000000000e-01, 9.98341487144877e-01, ), ( 5.00000000000000e+00, 5.00000000000000e-01, 9.90000000000000e-01, 9.99983487305151e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 1.00000000000000e-02, 2.53953079514517e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 1.00000000000000e-01, 3.57929880193458e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 2.50000000000000e-01, 4.24086532279680e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 5.00000000000000e-01, 5.00000000000000e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 7.50000000000000e-01, 5.75913467720320e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 9.00000000000000e-01, 6.42070119806542e-01, ), ( 1.00000000000000e+01, 1.00000000000000e+01, 9.90000000000000e-01, 7.46046920485483e-01, ), ];