Skip to content

Commit 17afd13

Browse files
add test for computing mud
1 parent 1e6ed7c commit 17afd13

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_mud_calculator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from pathlib import Path
2+
3+
import numpy as np
4+
import pytest
5+
6+
from diffpy.labpdfproc.mud_calculator import _extend_x_and_convolve, compute_mud
7+
8+
9+
def test_compute_mud(tmp_path):
10+
diameter, slit_width, x0, I0, mud, slope = 1, 0.1, 0, 1e5, 3, 0
11+
x_data = np.linspace(-1, 1, 50)
12+
convolved_I_data = _extend_x_and_convolve(x_data, diameter, slit_width, x0, I0, mud, slope)
13+
14+
directory = Path(tmp_path)
15+
file = directory / "testfile"
16+
with open(file, "w") as f:
17+
for x, I in zip(x_data, convolved_I_data):
18+
f.write(f"{x}\t{I}\n")
19+
20+
expected_mud = 3
21+
actual_mud = compute_mud(file)
22+
assert actual_mud == pytest.approx(expected_mud, rel=0.1, abs=0.1)

0 commit comments

Comments
 (0)