Skip to content

Commit

Permalink
delete text and redundant tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhua0320 committed Aug 13, 2024
1 parent ce1d97f commit 0faa2ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 52 deletions.
5 changes: 4 additions & 1 deletion src/diffpy/srmise/dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ def setdata(self, x, y, res):
if len(x) != len(y):
raise ValueError("Sequences x and y must have the same length.")
if res < 0:
raise ValueError("Resolution res must be non-negative.")
raise ValueError(
"Resolution is the Determines how closely clusters are formed in the clustering algorithm. "
"Please set it to be non-negative."
)
# Test for sorting?
self.x = x
self.y = y
Expand Down
64 changes: 13 additions & 51 deletions src/diffpy/srmise/tests/test_dataclusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,85 +34,47 @@ def test___eq__():
assert not expected == actual
attributes.update({attr_key: reset})

# In the set data test, we test for these cases.
# (1) x and y are non-empty array values, and res is positive (the most generic case)
# (2) x and y are non-empty array values, and res is 0 (will produce a msg that makes trivial clustering)
# (3) x and y are non-empty array values, and res is negative (will produce a ValueError,
# msg = please enter a non-negative res value)
# (4, 5) One of x and y is empty array, and res is positive
# (produce ValueError & msg "Sequences x and y must have the same length.", something like that)
# (6) Both x and y are empty array, and res is zero.


@pytest.mark.parametrize(
"inputs, expected",
[
(
# case (1)
{
"input_x": np.array([1, 2, 3]),
"input_y": np.array([3, 2, 1]),
"input_res": 4,
"x": np.array([1, 2, 3]),
"y": np.array([3, 2, 1]),
"res": 4,
},
DataClusters(np.array([1, 2, 3]), np.array([3, 2, 1]), 4),
),
(
# case (6)
{
"input_x": np.array([]),
"input_y": np.array([]),
"input_res": 0,
},
DataClusters(np.array([]), np.array([]), 0),
),
],
)
def test_set_data(inputs, expected):
actual = DataClusters(x=inputs["input_x"], y=inputs["input_y"], res=inputs["input_res"])
actual = DataClusters(x=inputs["x"], y=inputs["y"], res=inputs["res"])
assert actual == expected


@pytest.mark.parametrize(
"inputs, msg",
[
(
# case (4)
{
"input_x": np.array([]),
"input_y": np.array([3, 2]),
"input_res": 4,
},
"Sequences x and y must have the same length.",
),
(
# case (5)
{
"input_x": np.array([1, 2]),
"input_y": np.array([]),
"input_res": 4,
"x": np.array([1]),
"y": np.array([3, 2]),
"res": 4,
},
"Sequences x and y must have the same length.",
),
(
# case (3)
{
"input_x": np.array([1]),
"input_y": np.array([3]),
"input_res": -1,
},
"Resolution res must be non-negative.",
),
(
# case (2)
{
"input_x": np.array([1, 2, 3]),
"input_y": np.array([3, 2, 1]),
"input_res": 0,
"x": np.array([1]),
"y": np.array([3]),
"res": -1,
},
"Make trivial clustering, please make positive resolution.",
"Resolution is the Determines how closely clusters are formed in the clustering algorithm. "
"Please set it to be non-negative.",
),
],
)
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"])
DataClusters(x=inputs["x"], y=inputs["y"], res=inputs["res"])

0 comments on commit 0faa2ca

Please sign in to comment.