|
1 | 1 | import numpy as np |
2 | 2 | import pytest |
3 | 3 |
|
4 | | -from diffpy.utils.transforms import d_to_tth, q_to_tth, tth_to_d, tth_to_q |
| 4 | +from diffpy.utils.transforms import d_to_q, d_to_tth, q_to_d, q_to_tth, tth_to_d, tth_to_q |
5 | 5 |
|
6 | 6 | params_q_to_tth = [ |
7 | 7 | # UC1: Empty q values, no wavelength, return empty arrays |
@@ -64,7 +64,7 @@ def test_q_to_tth_bad(inputs, expected): |
64 | 64 | np.array([0, 1, 2, 3, 4, 5]), |
65 | 65 | ), |
66 | 66 | # UC3: User specified valid tth values between 0-180 degrees (with wavelength) |
67 | | - # expected q vales are sin15, sin30, sin45, sin60, sin90 |
| 67 | + # expected q values are sin15, sin30, sin45, sin60, sin90 |
68 | 68 | ( |
69 | 69 | [4 * np.pi, np.array([0, 30.0, 60.0, 90.0, 120.0, 180.0])], |
70 | 70 | np.array([0, 0.258819, 0.5, 0.707107, 0.866025, 1]), |
@@ -98,6 +98,40 @@ def test_tth_to_q_bad(inputs, expected): |
98 | 98 | tth_to_q(inputs[1], inputs[0]) |
99 | 99 |
|
100 | 100 |
|
| 101 | +params_q_to_d = [ |
| 102 | + # UC1: User specified empty q values |
| 103 | + ([np.array([])], np.array([])), |
| 104 | + # UC2: User specified valid q values |
| 105 | + ( |
| 106 | + [np.array([0, 1 * np.pi, 2 * np.pi, 3 * np.pi, 4 * np.pi, 5 * np.pi])], |
| 107 | + np.array([np.inf, 2, 1, 0.66667, 0.5, 0.4]), |
| 108 | + ), |
| 109 | +] |
| 110 | + |
| 111 | + |
| 112 | +@pytest.mark.parametrize("inputs, expected", params_q_to_d) |
| 113 | +def test_q_to_d(inputs, expected): |
| 114 | + actual = q_to_d(inputs[0]) |
| 115 | + assert np.allclose(actual, expected) |
| 116 | + |
| 117 | + |
| 118 | +params_d_to_q = [ |
| 119 | + # UC1: User specified empty d values |
| 120 | + ([np.array([])], np.array([])), |
| 121 | + # UC2: User specified valid d values |
| 122 | + ( |
| 123 | + [np.array([5 * np.pi, 4 * np.pi, 3 * np.pi, 2 * np.pi, np.pi, 0])], |
| 124 | + np.array([0.4, 0.5, 0.66667, 1, 2, np.inf]), |
| 125 | + ), |
| 126 | +] |
| 127 | + |
| 128 | + |
| 129 | +@pytest.mark.parametrize("inputs, expected", params_d_to_q) |
| 130 | +def test_d_to_q(inputs, expected): |
| 131 | + actual = d_to_q(inputs[0]) |
| 132 | + assert np.allclose(actual, expected) |
| 133 | + |
| 134 | + |
101 | 135 | params_tth_to_d = [ |
102 | 136 | # UC0: User specified empty tth values (without wavelength) |
103 | 137 | ([None, np.array([])], np.array([])), |
|
0 commit comments