starting to write tests

This commit is contained in:
Benoît Sierro
2021-10-21 09:12:53 +02:00
parent 7345eb8fea
commit 4c60835d3d
15 changed files with 109 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import os
import sys
from collections import MutableMapping
from collections.abc import MutableMapping
from pathlib import Path
from typing import Any, Set
@@ -93,13 +93,18 @@ def translate_parameters(d: dict[str, Any]) -> dict[str, Any]:
Parameters
----------
d : dict[str, Any]
[description]
any parameter dictionary WITHOUT "variable" part
Returns
-------
dict[str, Any]
[description]
translated parameters
"""
if {"variable", "Fiber"} & d.keys():
raise ValueError(
"The dict to translate should be a single parameter set "
"(no 'variable' nor 'Fiber' entry)"
)
old_names = dict(
interp_degree="interpolation_degree",
beta="beta2_coefficients",

View File

@@ -65,6 +65,7 @@ def _power_fact_single(x, n):
def _power_fact_array(x, n):
"""returns x^2/n!"""
result = np.ones(len(x), dtype=np.float64)
for k in range(n):
result = result * x / (n - k)

0
testing/test_cache.py Normal file
View File

0
testing/test_env.py Normal file
View File

View File

0
testing/test_legacy.py Normal file
View File

0
testing/test_logger.py Normal file
View File

100
testing/test_math.py Normal file
View File

@@ -0,0 +1,100 @@
import numpy as np
import pytest
import scgenerator.math as m
from math import factorial
def test__power_fact_array():
x = np.random.rand(5)
for i in range(5):
assert m._power_fact_array(x, i) == pytest.approx(x ** i / factorial(i))
def test__power_fact_single():
pass
def test_abs2():
x = np.random.rand(5)
assert m.abs2(5) == 25
assert m.abs2(2 - 2j) == 8
assert all(m.abs2(x) == abs(x) ** 2)
def test_all_zeros():
x = np.geomspace(0.1, 1, 100)
y = np.sin(1 / x)
target = [1 / (3 * np.pi), 1 / (2 * np.pi), 1 / np.pi]
assert m.all_zeros(x, y) == pytest.approx(target, abs=1e-4)
x = np.array([0, 1])
y = np.array([-1, 1])
assert all(m.all_zeros(x, y) == np.array([0.5]))
x = np.array([0, 1])
y = np.array([1, 1])
assert len(m.all_zeros(x, y)) == 0
def test_argclosest():
pass
def test_build_sim_grid():
pass
def test_indft():
pass
def test_indft_matrix():
pass
def test_jn_zeros():
pass
def test_length():
pass
def test_ndft():
pass
def test_ndft_matrix():
pass
def test_np_cache():
pass
def test_power_fact():
pass
def test_sigmoid():
pass
def test_span():
pass
def test_tspace():
pass
def test_u_nm():
pass
def test_update_frequency_domain():
pass
def test_wspace():
pass

View File

View File

0
testing/test_pbar.py Normal file
View File

0
testing/test_plotting.py Normal file
View File

View File

@@ -1,7 +1,6 @@
import numpy as np
import scgenerator as sc
import matplotlib.pyplot as plt
from pathlib import Path
def main():

0
testing/test_spectra.py Normal file
View File

0
testing/test_utils.py Normal file
View File