Skip to content

Commit 8eb8a7a

Browse files
authored
Merge pull request #17 from yucongalicechen/distances
Tests for setting distances for each grid point
2 parents 14b9bec + e1933d9 commit 8eb8a7a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/diffpy/labpdfproc/functions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def set_distances_at_angle(self, angle):
5959
self.secondary_distances.append(secondary)
6060

6161
def set_muls_at_angle(self, angle):
62-
# newly added docstring
6362
"""
6463
compute muls = exp(-mu*distance) for a given angle
6564
@@ -129,7 +128,7 @@ def _get_entry_exit_coordinates(self, coordinate, angle):
129128
xexit_root1, xexit_root2 = np.roots((1 + a**2, 2 * a * b, b**2 - self.radius**2))
130129
yexit_root1 = a * xexit_root1 + b
131130
yexit_root2 = a * xexit_root2 + b
132-
if yexit_root2 >= ygrid: # We pick the point above
131+
if yexit_root2 >= yexit_root1: # We pick the point above
133132
exit_point = (xexit_root2, yexit_root2)
134133
else:
135134
exit_point = (xexit_root1, yexit_root1)

src/diffpy/labpdfproc/tests/test_functions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,23 @@ def test_get_grid_points(inputs, expected):
1616
expected_grid_sorted = sorted(expected_grid)
1717
for actual_point, expected_point in zip(actual_grid_sorted, expected_grid_sorted):
1818
assert actual_point == pytest.approx(expected_point, rel=1e-4, abs=1e-6)
19+
20+
21+
params2 = [
22+
([1, 3, 1, 45], [0, 1.4142135, 1.4142135, 2, 2]),
23+
([1, 3, 1, 90], [0, 0, 2, 2, 2]),
24+
([1, 3, 1, 120], [0, 0, 2, 3, 1.73205]),
25+
([1, 4, 1, 30], [2.057347, 2.044451, 1.621801, 1.813330]),
26+
([1, 4, 1, 90], [1.885618, 1.885618, 2.552285, 1.218951]),
27+
([1, 4, 1, 140], [1.139021, 2.200102, 2.744909, 1.451264]),
28+
]
29+
30+
31+
@pytest.mark.parametrize("inputs, expected", params2)
32+
def test_set_distances_at_angle(inputs, expected):
33+
expected_distances = expected
34+
actual_gs = Gridded_circle(radius=inputs[0], n_points_on_diameter=inputs[1], mu=inputs[2])
35+
actual_gs.set_distances_at_angle(inputs[3])
36+
actual_distances_sorted = sorted(actual_gs.distances)
37+
expected_distances_sorted = sorted(expected_distances)
38+
assert actual_distances_sorted == pytest.approx(expected_distances_sorted, rel=1e-4, abs=1e-6)

0 commit comments

Comments
 (0)