Skip to content
Snippets Groups Projects
Commit 50ee7bc7 authored by Wolfgang Kastaun's avatar Wolfgang Kastaun
Browse files

Added unit test for numpy-based adaptive shift wrapper

parent 33c7e03c
No related branches found
No related tags found
No related merge requests found
Pipeline #388922 passed
......@@ -4,10 +4,15 @@ import numpy as np
import pytest
from lisainstrument.dynamic_delay_numpy import ShiftBC
from lisainstrument.fixed_shift_numpy import make_fixed_shift_lagrange_numpy
from lisainstrument.fixed_shift_numpy import (
AdaptiveShiftNumpy,
make_fixed_shift_lagrange_numpy,
)
def test_fixed_shift_lagrange_dask() -> None:
def test_fixed_shift_lagrange_numpy() -> None:
"""Test Lagrange interpolation of numpy arrays specialized to fixed shift"""
order = 5
t, dt = np.linspace(-5.345, 10.345, 1003, retstep=True)
......@@ -53,3 +58,41 @@ def test_fixed_shift_lagrange_dask() -> None:
with pytest.raises(RuntimeError):
op2_np(y, -d)
def test_adaptive_shift_numpy() -> None:
"""Test AdaptiveShiftNumpy wrapper
Only checks that it calls correct methods based on argument type combinations.
"""
def mock_fix(d: np.ndarray, s: float) -> np.ndarray:
"""Bogus but unique result to check this function was used"""
return d * s
def mock_dyn(d: np.ndarray, s: np.ndarray) -> np.ndarray:
"""Bogus but unique result to check this function was used"""
return d / s
mock_fsamp = 13
op = AdaptiveShiftNumpy(mock_fix, mock_dyn, mock_fsamp)
y_fix = 12.0
y_dyn = np.ones(10) * y_fix
s_fix = 6.0
s_dyn = np.ones(10) * s_fix
r_dyn_fix = op(y_dyn, s_fix)
assert np.all(r_dyn_fix == mock_fix(y_dyn, s_fix * mock_fsamp))
r_dyn_dyn = op(y_dyn, s_dyn)
assert np.all(r_dyn_dyn == mock_dyn(y_dyn, s_dyn * mock_fsamp))
r_fix_fix = op(y_fix, s_fix)
assert r_fix_fix == y_fix
r_fix_zero = op(y_fix, 0.0)
assert r_fix_zero == y_fix
r_fix_dyn = op(y_fix, s_dyn)
assert r_fix_dyn == y_fix
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment