Skip to content

Commit 14b9bec

Browse files
authored
Merge pull request #15 from yucongalicechen/gridpts
Tests for grid points
2 parents 1301409 + 7385ba9 commit 14b9bec

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/diffpy/labpdfproc/functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _get_grid_points(self):
2424
"""
2525
xs = np.linspace(-self.radius, self.radius, self.npoints)
2626
ys = np.linspace(-self.radius, self.radius, self.npoints)
27-
self.grid = [(x, y) for x in xs for y in ys if x**2 + y**2 <= self.radius**2]
27+
self.grid = {(x, y) for x in xs for y in ys if x**2 + y**2 <= self.radius**2}
2828
self.total_points_in_grid = len(self.grid)
2929

3030
# def get_coordinate_index(self, coordinate): # I think we probably dont need this function?
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from diffpy.labpdfproc.functions import Gridded_circle
4+
5+
params1 = [
6+
([0.5, 3, 1], {(0.0, -0.5), (0.0, 0.0), (0.5, 0.0), (-0.5, 0.0), (0.0, 0.5)}),
7+
([1, 4, 1], {(-0.333333, -0.333333), (0.333333, -0.333333), (-0.333333, 0.333333), (0.333333, 0.333333)}),
8+
]
9+
10+
11+
@pytest.mark.parametrize("inputs, expected", params1)
12+
def test_get_grid_points(inputs, expected):
13+
expected_grid = expected
14+
actual_gs = Gridded_circle(radius=inputs[0], n_points_on_diameter=inputs[1], mu=inputs[2])
15+
actual_grid_sorted = sorted(actual_gs.grid)
16+
expected_grid_sorted = sorted(expected_grid)
17+
for actual_point, expected_point in zip(actual_grid_sorted, expected_grid_sorted):
18+
assert actual_point == pytest.approx(expected_point, rel=1e-4, abs=1e-6)

0 commit comments

Comments
 (0)