Skip to content

Commit

Permalink
add condition on x and res are incompatible, update test.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhua0320 committed Aug 10, 2024
1 parent ca8a169 commit 2105474
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/diffpy/srmise/dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ def setdata(self, x, y, res):
self.x = x
self.y = y
self.res = res
# check x and res value are compatible.
if x.size == 0 and res != 0:
raise ValueError("It produces trivial clustering, please set 'res' to positive values.")
# If x sequence size is empty, set the object into Initialized state.
if x.size == 0 and res == 0:
self.data_order = np.array([])
Expand Down
24 changes: 3 additions & 21 deletions src/diffpy/srmise/tests/test_dataclusters.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
import numpy as np
import pytest

from diffpy.srmise.dataclusters import DataClusters


@pytest.mark.parametrize(
"inputs, expected",
[
(
{
"input_x": np.array([1, 2, 3]),
"input_y": np.array([3, 2, 1]),
"input_res": 4,
},
{
"x": np.array([]),
"y": np.array([]),
"res": 0,
},
),
],
)
def test_clear(inputs, expected):
def test_clear():
# Initialize DataClusters with input parameters
actual = DataClusters(x=inputs["input_x"], y=inputs["input_y"], res=inputs["input_res"])
expected = DataClusters(x=expected["x"], y=expected["y"], res=expected["res"])
actual = DataClusters(x=np.array([1, 2, 3]), y=np.array([3, 2, 1]), res=4)
expected = DataClusters(x=np.array([]), y=np.array([]), res=0)
# Perform the clear operation
actual.clear()
assert actual == expected

0 comments on commit 2105474

Please sign in to comment.