Skip to content

Commit ea9de8b

Browse files
authored
Merge pull request #37 from TomasLenc/tomo-tests
Add tests for utils
2 parents 709f3fd + 1c1d478 commit ea9de8b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
import pytest
3+
4+
from phys2denoise.metrics.utils import mirrorpad_1d, rms_envelope_1d
5+
6+
7+
@pytest.fixture
8+
def short_arr():
9+
return np.array([0,1,2,3,4,5,6,7,8,9])
10+
11+
def test_mirrorpad(short_arr):
12+
"""Basic test for flipping and padding the input array"""
13+
arr_mirror = mirrorpad_1d(short_arr, buffer=3)
14+
expected_arr_mirror = np.array([2,1,0,0,1,2,3,4,5,6,7,8,9,9,8,7])
15+
assert all(arr_mirror == expected_arr_mirror)
16+
17+
18+
def test_mirrorpad_exception(short_arr):
19+
"""When passing array that is too short to perform mirrorpadding, the
20+
function should give an error."""
21+
arr = np.array(short_arr)
22+
with pytest.raises(Exception) as e_info:
23+
arr_mirror = mirrorpad_1d(short_arr)
24+
25+
26+
def test_rms_envelope():
27+
"""Basic test for rms envelope calculation. When the input is constant, we
28+
should get an output with the same size and the same constant value. """
29+
arr = np.tile(2.,10)
30+
arr_env = rms_envelope_1d(arr, window=4)
31+
expected_arr_env = np.tile(2.,10)
32+
assert all(arr_env == expected_arr_env)

0 commit comments

Comments
 (0)