Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test for dataclusters #54

Merged
merged 13 commits into from
Aug 10, 2024
Merged
Prev Previous commit
Next Next commit
add two more tests for DataClusters class function.
  • Loading branch information
stevenhua0320 committed Aug 8, 2024
commit b959a0915493ff81a2349dfc3b9f7a98a737895f
79 changes: 79 additions & 0 deletions src/diffpy/srmise/tests/test_dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,82 @@ def test_clear(inputs, expected):
if isinstance(expected_value, np.ndarray)
else getattr(actual, attr) == expected_value
)


@pytest.mark.parametrize(
sbillinge marked this conversation as resolved.
Show resolved Hide resolved
"inputs, expected",
[
(
{
"input_x": np.array([1, 2, 3]),
"input_y": np.array([3, 2, 1]),
"input_res": 4,
},
DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 4),
),
(
sbillinge marked this conversation as resolved.
Show resolved Hide resolved
{
"input_x": np.array([1]),
"input_y": np.array([3]),
"input_res": 1,
},
DataClusters(np.array([1]), np.array([3]), 1),
),
],
)
def test_reset_clusters(inputs, expected):
actual = DataClusters(x=inputs["input_x"], y=inputs["input_y"], res=inputs["input_res"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see comment above about naming these.

actual.reset_clusters()
assert actual == expected


@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see comments above on this too. Please start by doing a more informative docstring for each method you are testing. This helps to understand what each method is doing. It will also appear in the docs when we build them.

"inputs, expected",
[
(
{
"input_x": np.array([1, 2, 3]),
"input_y": np.array([3, 2, 1]),
"input_res": 4,
},
DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 4),
),
(
{
"input_x": np.array([1]),
"input_y": np.array([3]),
"input_res": 1,
},
DataClusters(np.array([1]), np.array([3]), 1),
),
],
)
def test_set_data(inputs, expected):
actual = DataClusters(x=inputs["input_x"], y=inputs["input_y"], res=inputs["input_res"])
assert actual == expected


@pytest.mark.parametrize(
"inputs, msg",
[
(
{
"input_x": np.array([1, 2, 3]),
"input_y": np.array([3, 2]),
"input_res": 4,
},
"Sequences x and y must have the same length.",
),
(
{
"input_x": np.array([1]),
"input_y": np.array([3]),
"input_res": -1,
},
"Resolution res must be greater than 0.",
),
],
)
def test_set_data_order_bad(inputs, msg):
with pytest.raises(ValueError, match=msg):
DataClusters(x=inputs["input_x"], y=inputs["input_y"], res=inputs["input_res"])
Loading