diff --git a/src/itmlogic/qerf.py b/src/itmlogic/qerf.py index 0887a3c..079d41c 100644 --- a/src/itmlogic/qerf.py +++ b/src/itmlogic/qerf.py @@ -1,20 +1,22 @@ +import math + def qerf(z): """ - The standard normal complementary probability - see function in + The standard normal complementary probability - see function in C. Hastings, Jr. (1955). The maximum error should be 7.5x10^-8. Parameters ---------- z : TODO: Type TODO: Description - + Output ------ qerf1 : float TODO: """ - + b1 = 0.319381530 b2 = -0.356563782 b3 = 1.781477937 @@ -24,22 +26,23 @@ def qerf(z): rrt2pi = 0.398942280 - x = z[0] + x = z t = abs(x) if t >= 10: - + qerf1 = 0 - + else: - + t = rp / (t + rp) qerf1 = ( - exp(-0.5 * x**2) * rrt2pi * + math.exp(-0.5 * x**2) * rrt2pi * ((((b5 * t + b4) * t + b3) * t + b2) * t + b1) * t ) - # if (x<0.) qerf1=1.-qerf1 TODO: + if x < 0: + qerf1 = 1 - qerf1 - return qerf1 \ No newline at end of file + return qerf1 diff --git a/tests/test_aknfe.py b/tests/test_aknfe.py index 3aab128..e3b8c2b 100644 --- a/tests/test_aknfe.py +++ b/tests/test_aknfe.py @@ -3,8 +3,7 @@ def test_aknfe(): + assert round(aknfe(2), 2) == 16.36 + assert round(aknfe(3), 2) == 17.99 assert round(aknfe(5), 2) == 20.04 assert round(aknfe(6), 2) == 20.73 - - - \ No newline at end of file diff --git a/tests/test_fht.py b/tests/test_fht.py index 04b25fa..39eaee2 100644 --- a/tests/test_fht.py +++ b/tests/test_fht.py @@ -12,5 +12,6 @@ def test_fht(): assert actual_answer == expected_answer + assert round(fht(150, 20), 2) == 11.05 - \ No newline at end of file + assert round(fht(150, 1e-6), 2) == -29.96 diff --git a/tests/test_h0f.py b/tests/test_h0f.py index f8ccf1d..ae68f18 100644 --- a/tests/test_h0f.py +++ b/tests/test_h0f.py @@ -12,3 +12,11 @@ def test_h0f(): expected_answer = 34.28154717133048 assert actual_answer == expected_answer + + actual_answer = h0f(2, -1) + + assert round(actual_answer, 2) == 9.33 + + actual_answer = h0f(2, 6) + + assert round(actual_answer, 2) == 18.53 diff --git a/tests/test_qerf.py b/tests/test_qerf.py index 8385b45..9ab646d 100644 --- a/tests/test_qerf.py +++ b/tests/test_qerf.py @@ -1,4 +1,8 @@ import pytest from itmlogic.qerf import qerf -# def test_qerf(): +def test_qerf(): + + assert round(qerf(-1),4) == 0.8413 + assert round(qerf(1),4) == 0.1587 + assert round(qerf(10),4) == 0