Skip to content

Commit b490d5e

Browse files
test parameters now inputs and parameters, intermediate commit for refactoring grid tests
1 parent 20a14fa commit b490d5e

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/diffpy/labpdfproc/functions.py

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

2929
# def get_coordinate_index(self, coordinate): # I think we probably dont need this function?

src/diffpy/labpdfproc/tests/test_functions.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,19 @@
44

55
# Define test parameters
66
params1 = [
7-
([0.5, 3, 1, {(0.0, -0.5), (0.0, 0.0), (-0.5, 0.0), (0.5, 0.0), (0.0, 0.5)}, 5]),
8-
([1, 4, 1, {(-0.333333, -0.333333), (0.333333, -0.333333), (-0.333333, 0.333333), (0.333333, 0.333333)}, 4]),
7+
([0.5, 3, 1], {(0.0, -0.5), (0.0, 0.0), (0.5, 0.0), (-0.5, 0.0), (0.0, 0.5)}),
8+
([1, 4, 1], {(-0.333333, -0.333333), (0.333333, -0.333333), (-0.333333, 0.333333), (0.333333, 0.333333)}),
99
]
1010

1111

1212
# Define the test function
13-
@pytest.mark.parametrize("params1", params1)
14-
def test_get_grid_points(params1):
15-
radius, n_points_on_diameter, mu, expected_grid, expected_total_points = params1
13+
@pytest.mark.parametrize("inputs, expected", params1)
14+
def test_get_grid_points(inputs, expected):
15+
expected_grid = expected
16+
actual_gs = Gridded_circle(radius=inputs[0], n_points_on_diameter=inputs[1], mu=inputs[2])
17+
assert actual_gs.grid == expected_grid
1618

17-
# Perform the test
18-
actual_gs = Gridded_circle(radius=radius, n_points_on_diameter=n_points_on_diameter, mu=mu)
1919

20-
# Sort both sets of points to compare
21-
actual_grid_sorted = sorted(actual_gs.grid)
22-
expected_grid_sorted = sorted(expected_grid)
23-
24-
# Assertions
25-
assert actual_gs.total_points_in_grid == expected_total_points
26-
for actual_point, expected_point in zip(actual_grid_sorted, expected_grid_sorted):
27-
assert actual_point == pytest.approx(expected_point, rel=1e-4, abs=1e-6)
20+
# assert actual_gs.grid == pytest.approx(expected_grid)
21+
# for actual_point, expected_point in zip(actual_grid_sorted, expected_grid_sorted):
22+
# assert actual_point == pytest.approx(expected_point, rel=1e-4, abs=1e-6)

0 commit comments

Comments
 (0)