import pytest
import numpy as np
import scirs2
class TestGammaFunctions:
def test_gamma(self):
assert abs(scirs2.gamma_py(1.0) - 1.0) < 1e-10
assert abs(scirs2.gamma_py(2.0) - 1.0) < 1e-10
assert abs(scirs2.gamma_py(3.0) - 2.0) < 1e-10
assert abs(scirs2.gamma_py(4.0) - 6.0) < 1e-10
assert abs(scirs2.gamma_py(5.0) - 24.0) < 1e-10
def test_gamma_array(self):
x = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
expected = np.array([1.0, 1.0, 2.0, 6.0, 24.0])
result = scirs2.gamma_array_py(x)
np.testing.assert_allclose(result, expected, rtol=1e-10)
def test_lgamma(self):
assert abs(scirs2.lgamma_py(5.0) - np.log(24.0)) < 1e-10
def test_digamma(self):
result = scirs2.digamma_py(1.0)
assert abs(result + 0.5772156649) < 0.001
def test_beta(self):
assert abs(scirs2.beta_py(1.0, 1.0) - 1.0) < 1e-10
assert abs(scirs2.beta_py(2.0, 3.0) - 1.0/12.0) < 1e-10
class TestBesselFunctions:
def test_j0(self):
assert abs(scirs2.j0_py(0.0) - 1.0) < 1e-10
assert abs(scirs2.j0_py(1.0) - 0.7652) < 0.001
def test_j1(self):
assert abs(scirs2.j1_py(0.0)) < 1e-10
assert abs(scirs2.j1_py(1.0) - 0.4401) < 0.001
def test_jn(self):
assert abs(scirs2.jn_py(2, 0.0)) < 1e-10
assert abs(scirs2.jn_py(3, 0.0)) < 1e-10
def test_y0(self):
assert abs(scirs2.y0_py(1.0) - 0.0883) < 0.001
def test_y1(self):
assert abs(scirs2.y1_py(1.0) + 0.7812) < 0.001
def test_yn(self):
result = scirs2.yn_py(2, 1.0)
assert isinstance(result, float)
def test_i0(self):
assert abs(scirs2.i0_py(0.0) - 1.0) < 1e-10
assert abs(scirs2.i0_py(1.0) - 1.266) < 0.001
def test_i1(self):
assert abs(scirs2.i1_py(0.0)) < 1e-10
assert abs(scirs2.i1_py(1.0) - 0.565) < 0.001
def test_k0(self):
assert abs(scirs2.k0_py(1.0) - 0.4611) < 0.001
def test_k1(self):
assert abs(scirs2.k1_py(1.0) - 0.5187) < 0.001
def test_bessel_array(self):
x = np.array([0.0, 1.0, 2.0])
result = scirs2.j0_array_py(x)
assert len(result) == 3
assert abs(result[0] - 1.0) < 1e-10
class TestErrorFunctions:
def test_erf(self):
assert abs(scirs2.erf_py(0.0)) < 1e-10
assert abs(scirs2.erf_py(3.0) - 0.9999779) < 0.000001
def test_erfc(self):
assert abs(scirs2.erfc_py(0.0) - 1.0) < 1e-10
x = 1.5
assert abs(scirs2.erfc_py(x) - (1.0 - scirs2.erf_py(x))) < 1e-10
def test_erfinv(self):
x = 0.5
assert abs(scirs2.erfinv_py(scirs2.erf_py(x)) - x) < 0.001
def test_erfcinv(self):
x = 0.5
assert abs(scirs2.erfcinv_py(scirs2.erfc_py(x)) - x) < 0.001
def test_erfcx(self):
x = 1.0
expected = np.exp(x**2) * scirs2.erfc_py(x)
assert abs(scirs2.erfcx_py(x) - expected) < 0.001
def test_erfi(self):
assert abs(scirs2.erfi_py(0.0)) < 1e-10
def test_dawsn(self):
assert abs(scirs2.dawsn_py(0.0)) < 1e-10
def test_erf_array(self):
x = np.array([0.0, 0.5, 1.0])
result = scirs2.erf_array_py(x)
assert len(result) == 3
assert abs(result[0]) < 1e-10
class TestCombinatorial:
def test_factorial(self):
assert scirs2.factorial_py(0) == 1.0
assert scirs2.factorial_py(1) == 1.0
assert scirs2.factorial_py(2) == 2.0
assert scirs2.factorial_py(3) == 6.0
assert scirs2.factorial_py(4) == 24.0
assert scirs2.factorial_py(5) == 120.0
def test_comb(self):
assert scirs2.comb_py(5, 0) == 1.0
assert scirs2.comb_py(5, 1) == 5.0
assert scirs2.comb_py(5, 2) == 10.0
assert scirs2.comb_py(5, 3) == 10.0
assert scirs2.comb_py(5, 5) == 1.0
def test_perm(self):
assert scirs2.perm_py(5, 0) == 1.0
assert scirs2.perm_py(5, 1) == 5.0
assert scirs2.perm_py(5, 2) == 20.0
assert scirs2.perm_py(5, 3) == 60.0
assert scirs2.perm_py(5, 5) == 120.0
class TestEllipticIntegrals:
def test_ellipk(self):
result = scirs2.ellipk_py(0.0)
assert abs(result - np.pi/2) < 0.001
def test_ellipe(self):
result = scirs2.ellipe_py(0.0)
assert abs(result - np.pi/2) < 0.001
def test_ellipkinc(self):
result = scirs2.ellipkinc_py(np.pi/2, 0.0)
assert abs(result - np.pi/2) < 0.001
def test_ellipeinc(self):
result = scirs2.ellipeinc_py(np.pi/2, 0.0)
assert abs(result - np.pi/2) < 0.001