Skip to content

Commit 2f11634

Browse files
add tests for conversions between tth, q, and d
1 parent 8667f3b commit 2f11634

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

tests/test_diffraction_objects.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,56 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):
231231
assert (diffraction_object1 == diffraction_object2) == expected
232232

233233

234+
def test_q_to_tth():
235+
actual = Diffraction_object(wavelength=0.71)
236+
setattr(actual, "on_q", [[0, 4.58087], [1, 1]])
237+
actual_tth = actual.q_to_tth()
238+
expected_tth = [0, 30]
239+
assert np.allclose(actual_tth, expected_tth)
240+
241+
242+
def test_tth_to_q():
243+
actual = Diffraction_object(wavelength=0.71)
244+
setattr(actual, "on_tth", [[0, 30], [1, 1]])
245+
actual_q = actual.tth_to_q()
246+
expected_q = [0, 4.58087]
247+
assert np.allclose(actual_q, expected_q)
248+
249+
250+
def test_q_to_d():
251+
actual = Diffraction_object(wavelength=0.71)
252+
setattr(actual, "on_q", [[0, 4.58087], [1, 1]])
253+
actual_d = actual.q_to_d()
254+
expected_d = [62831853071.8, 1.37161]
255+
assert np.allclose(actual_d, expected_d)
256+
257+
258+
def test_d_to_q():
259+
actual = Diffraction_object(wavelength=0.71)
260+
setattr(actual, "on_d", [[1e10, 1.37161], [1, 1]])
261+
actual_q = actual.d_to_q()
262+
expected_q = [0, 4.58087]
263+
assert np.allclose(actual_q, expected_q)
264+
265+
266+
def test_tth_to_d():
267+
actual = Diffraction_object(wavelength=0.71)
268+
setattr(actual, "on_tth", [[0, 30], [1, 1]])
269+
actual_d = actual.tth_to_d()
270+
expected_d = [3550000000, 1.37161]
271+
assert np.allclose(actual_d, expected_d)
272+
273+
274+
def test_d_to_tth():
275+
actual = Diffraction_object(wavelength=0.71)
276+
setattr(actual, "on_d", [[1e10, 1.37161], [1, 1]])
277+
actual_tth = actual.d_to_tth()
278+
expected_tth = [0, 30]
279+
assert np.allclose(actual_tth, expected_tth)
280+
281+
282+
#def test_set_all_arrays():
283+
234284
def test_dump(tmp_path, mocker):
235285
x, y = np.linspace(0, 5, 6), np.linspace(0, 5, 6)
236286
directory = Path(tmp_path)

0 commit comments

Comments
 (0)