Initial commit
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
11
tests/test_complex_quad.py
Normal file
11
tests/test_complex_quad.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import numpy as np
|
||||
import pynam.complex_quad
|
||||
|
||||
|
||||
def test_complex_quad():
|
||||
actual = pynam.complex_quad.complex_quadrature(lambda x: x**2 + 1j * x**3, 0, 6)[0]
|
||||
# int_1^6 dx x^2 + i x^3 should equal (1/3)6^3 + (i/4)6^4
|
||||
np.testing.assert_almost_equal(
|
||||
actual, (6**3)/3 + 1j*(6**4)/4,
|
||||
decimal=7, err_msg='complex quadrature is broken', verbose=True
|
||||
)
|
||||
103
tests/test_low_k_nam.py
Normal file
103
tests/test_low_k_nam.py
Normal file
@@ -0,0 +1,103 @@
|
||||
import pynam.low_k_nam
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2), 7 / (2 * np.sqrt(6))),
|
||||
((2, 0.25), -5j / np.sqrt(39))
|
||||
])
|
||||
def test_g(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.low_k_nam.g(*test_input), expected,
|
||||
decimal=7, err_msg='g function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 1, 0), 8 / 5),
|
||||
((1, 1, 1), 3 / 5 + 11j / 15),
|
||||
((1, 0, 1), 16j / 15)
|
||||
])
|
||||
def test_f(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.low_k_nam.f(*test_input), expected,
|
||||
decimal=7, err_msg='f function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((2, 3, 1, 0), 1.42546694754),
|
||||
((1, 2, 3, 4), 0.0206212167 + 0.4411134527j)
|
||||
])
|
||||
def test_i1(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.low_k_nam.i1(*test_input), expected,
|
||||
decimal=7, err_msg='i1 function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((2, 3, 1, 0), 1.47903168398),
|
||||
((1, 2, 3, 4), 0.079491440779 + 0.441113452718j)
|
||||
])
|
||||
def test_i2(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.low_k_nam.i2(*test_input), expected,
|
||||
decimal=7, err_msg='i1 function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 3, 4), 0.228292),
|
||||
])
|
||||
def test_a(test_input, expected):
|
||||
actual = np.real_if_close(pynam.low_k_nam.a(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='a function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((2, 1, 2, 0, 4), 0.479529593125),
|
||||
((100, 1, 2, 3, 4), -2.62529549942e-6 + 2.60588e-12j),
|
||||
])
|
||||
def test_b_int(test_input, expected):
|
||||
actual = np.real_if_close(pynam.low_k_nam.b_int(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='b int function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 0, 4), 3.514889721181435),
|
||||
((1, 2, 3, 4), -0.0598057 + 0.437146j),
|
||||
])
|
||||
def test_b(test_input, expected):
|
||||
actual = np.real_if_close(pynam.low_k_nam.b(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='b function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 0, 4), 0),
|
||||
((1, 2, 3, 4), 0.98358 + 0.648221j),
|
||||
])
|
||||
def test_sigma_alk(test_input, expected):
|
||||
actual = np.real_if_close(pynam.low_k_nam.sigma_nam_alk(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='b function is off'
|
||||
)
|
||||
|
||||
|
||||
def test_sigma_alk_benchmark(benchmark):
|
||||
result = benchmark(pynam.low_k_nam.sigma_nam_alk, 1, 2, 3, 4)
|
||||
np.testing.assert_almost_equal(
|
||||
result, 0.98358 + 0.648221j,
|
||||
decimal=6, err_msg='b function is off'
|
||||
)
|
||||
5
tests/test_pynam.py
Normal file
5
tests/test_pynam.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from pynam import __version__
|
||||
|
||||
|
||||
def test_version():
|
||||
assert __version__ == '0.1.0'
|
||||
120
tests/test_sigma_nam.py
Normal file
120
tests/test_sigma_nam.py
Normal file
@@ -0,0 +1,120 @@
|
||||
import pynam.sigma_nam
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2), 7 / (2 * np.sqrt(6))),
|
||||
((2, 0.25), -5j / np.sqrt(39))
|
||||
])
|
||||
def test_g(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.sigma_nam.g(*test_input), expected,
|
||||
decimal=7, err_msg='g function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 0), 2),
|
||||
((1, 2, 3), 2 - 3j),
|
||||
((1, 0, 3), -3j)
|
||||
])
|
||||
def test_s(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.sigma_nam.s(*test_input), expected,
|
||||
decimal=7, err_msg='s function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 0), 4 - 3 * np.log(3)),
|
||||
((1, 1, 0.1), 1.7258022209219421 + 0.4146045220413866j),
|
||||
((1, 2, 1), 0.535971651563 + 0.291580606867j),
|
||||
((1, 0, 1), (np.pi - 2)*1j),
|
||||
((2, 1.09637631718, 0), 0.97892512273 + 1.09875591859j),
|
||||
((2, 1, 0), 0.91197960825 + 1.17809724510j)
|
||||
])
|
||||
def test_f(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.sigma_nam.f(*test_input), expected,
|
||||
decimal=7, err_msg='f function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((2, 3, 1, 0), 1.43292419807),
|
||||
((1, 2, 3, 4), 0.020963572915 + 0.441546735048j),
|
||||
((1, 2, 2, 0), 2.24702466263660598724031013350450660504 + 2.6687342075059525776833106878900822165j)
|
||||
])
|
||||
def test_i1(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.sigma_nam.i1(*test_input), expected,
|
||||
decimal=7, err_msg='i1 function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((2, 3, 1, 0), 1.48649022993),
|
||||
((1, 2, 3, 4), 0.079899419983 + 0.441546735048j),
|
||||
((1, 2, 2, 0), 2.5083371377336783093007366990156440969 + 2.6687342075059525776833106878900822165j)
|
||||
])
|
||||
def test_i2(test_input, expected):
|
||||
np.testing.assert_almost_equal(
|
||||
pynam.sigma_nam.i2(*test_input), expected,
|
||||
decimal=7, err_msg='i1 function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 3, 4), 0.228396),
|
||||
])
|
||||
def test_a(test_input, expected):
|
||||
actual = np.real_if_close(pynam.sigma_nam.a(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='a function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((2, 1, 2, 0, 4), 0.19089933550122580816258795500979108668 + 0.30273783507819906415704926284048453889j),
|
||||
((100, 1, 2, 3, 4), -2.62529549976e-6 + 2.60765e-12j),
|
||||
])
|
||||
def test_b_int(test_input, expected):
|
||||
actual = np.real_if_close(pynam.sigma_nam.b_int(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='b int function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 0, 4), 1.23149 + 2.08627j),
|
||||
((1, 2, 3, 4), -0.0595819 + 0.437385j),
|
||||
])
|
||||
def test_b(test_input, expected):
|
||||
actual = np.real_if_close(pynam.sigma_nam.b(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, actual,
|
||||
decimal=6, err_msg='b function is off'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_input,expected", [
|
||||
((1, 2, 0, 4), 0),
|
||||
((1, 2, 3, 4), 0.984117 + 0.647951j),
|
||||
])
|
||||
def test_sigma_nam(test_input, expected):
|
||||
actual = np.real_if_close(pynam.sigma_nam.sigma_nam(*test_input))
|
||||
np.testing.assert_almost_equal(
|
||||
actual, expected,
|
||||
decimal=6, err_msg='sigma_nam function is off'
|
||||
)
|
||||
|
||||
|
||||
def test_sigma_nam_benchmark(benchmark):
|
||||
result = benchmark(pynam.sigma_nam.sigma_nam, 1, 2, 3, 4)
|
||||
np.testing.assert_almost_equal(
|
||||
result, 0.984117 + 0.647951j,
|
||||
decimal=6, err_msg='sigma nam benchmrak function is off'
|
||||
)
|
||||
Reference in New Issue
Block a user