Skip to content

Commit 638b216

Browse files
update tests for set_all_arrays and edge cases
1 parent 2de70ed commit 638b216

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

tests/test_diffraction_objects.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected):
233233

234234
def test_q_to_tth():
235235
actual = Diffraction_object(wavelength=4 * np.pi)
236-
setattr(actual, "on_q", [[0, 0.2, 0.4, 0.6, 0.8, 1], [1, 2, 3, 4, 5, 6]])
236+
setattr(actual, "on_q", [[0, 0.2, 0.4, 0.6, 0.8, 1, 40, 60], [1, 2, 3, 4, 5, 6, 7, 8]])
237237
actual_tth = actual.q_to_tth()
238238
# expected tth values are 2 * arcsin(q)
239-
expected_tth = [0, 23.07392, 47.15636, 73.73980, 106.26020, 180]
239+
# when q gets large, we set tth = 180
240+
# we allow q to exceed QMAX for user inputs
241+
expected_tth = [0, 23.07392, 47.15636, 73.73980, 106.26020, 180, 180, 180]
240242
assert np.allclose(actual_tth, expected_tth)
241243

242244

@@ -278,37 +280,38 @@ def test_tth_to_d():
278280

279281
def test_d_to_tth():
280282
actual = Diffraction_object(wavelength=2)
281-
setattr(actual, "on_d", [[0, 2, 4, 6, 8, 100], [1, 2, 3, 4, 5, 6]])
283+
setattr(actual, "on_d", [[0, 2, 4, 6, 8, 100, 200], [1, 2, 3, 4, 5, 6, 7]])
282284
actual_tth = actual.d_to_tth()
283285
# expected tth values are 2*arcsin(1/d), in reverse order
284286
# when d is 0, we set tth to 180
285-
expected_tth = [1.14593, 14.36151, 19.18814, 28.95502, 60, 180]
287+
# we allow d to exceed DMAX=100 for user inputs
288+
expected_tth = [0.57296, 1.14593, 14.36151, 19.18814, 28.95502, 60, 180]
286289
assert np.allclose(actual_tth, expected_tth)
287290

288291

289292
params_array = [
290-
(["q", "on_q", [4.58087, 8.84956], [1, 2]]),
291-
(["tth", "on_tth", [30, 60], [1, 2]]),
292-
(["d", "on_d", [1.37161, 0.71], [1, 2]]),
293+
(["tth", "on_tth", [30, 60, 90, 120, 150], [1, 2, 3, 4, 5]]),
294+
(["q", "on_q", [1.626208, 3.141593, 4.442883, 5.441398, 6.069091], [1, 2, 3, 4, 5]]),
295+
(["d", "on_d", [1.035276, 1.154701, 1.414214, 2, 3.863703], [1, 2, 3, 4, 5]]),
293296
]
294297

295298

296299
@pytest.mark.parametrize("inputs", params_array)
297300
def test_set_all_arrays(inputs):
298301
input_xtype, on_xtype, xarray, yarray = inputs
299302
expected_values = {
300-
"on_tth": [np.array([30, 60]), np.array([1, 2])],
301-
"on_q": [np.array([4.58087, 8.84956]), np.array([1, 2])],
302-
"on_d": [np.array([1.37161, 0.71]), np.array([1, 2])],
303+
"on_tth": [np.array([30, 60, 90, 120, 150]), np.array([1, 2, 3, 4, 5])],
304+
"on_q": [np.array([1.626208, 3.141593, 4.442883, 5.441398, 6.069091]), np.array([1, 2, 3, 4, 5])],
305+
"on_d": [np.array([1.035276, 1.154701, 1.414214, 2, 3.863703]), np.array([1, 2, 3, 4, 5])],
303306
"tthmin": 30,
304-
"tthmax": 60,
305-
"qmin": 4.58087,
306-
"qmax": 8.84956,
307-
"dmin": 1.37161,
308-
"dmax": 0.71,
307+
"tthmax": 150,
308+
"qmin": 1.626208,
309+
"qmax": 6.069091,
310+
"dmin": 1.035276,
311+
"dmax": 3.863703,
309312
}
310313

311-
actual = Diffraction_object(wavelength=0.71)
314+
actual = Diffraction_object(wavelength=2)
312315
setattr(actual, "input_xtype", input_xtype)
313316
setattr(actual, on_xtype, [xarray, yarray])
314317
actual.set_all_arrays()

0 commit comments

Comments
 (0)