From 210547474ae6a2afcf3f36871712e4d4eb979c64 Mon Sep 17 00:00:00 2001 From: stevenhua0320 Date: Sat, 10 Aug 2024 22:17:28 +0800 Subject: [PATCH] add condition on x and res are incompatible, update test. --- src/diffpy/srmise/dataclusters.py | 3 +++ src/diffpy/srmise/tests/test_dataclusters.py | 24 +++----------------- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/diffpy/srmise/dataclusters.py b/src/diffpy/srmise/dataclusters.py index 4cb46be..c453a79 100644 --- a/src/diffpy/srmise/dataclusters.py +++ b/src/diffpy/srmise/dataclusters.py @@ -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([]) diff --git a/src/diffpy/srmise/tests/test_dataclusters.py b/src/diffpy/srmise/tests/test_dataclusters.py index 62932d9..ecd243e 100644 --- a/src/diffpy/srmise/tests/test_dataclusters.py +++ b/src/diffpy/srmise/tests/test_dataclusters.py @@ -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