Skip to content

Commit 93a08d5

Browse files
committed
fixes seeds
Signed-off-by: Wenqi Li <[email protected]>
1 parent b98f016 commit 93a08d5

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

tests/test_rand_lambdad.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from monai.transforms import Randomizable
1717
from monai.transforms.utility.dictionary import RandLambdad
18-
from tests.utils import NumpyImageTestCase2D
1918

2019

2120
class RandTest(Randomizable):
@@ -24,26 +23,25 @@ class RandTest(Randomizable):
2423
"""
2524

2625
def randomize(self, data=None):
27-
self.set_random_state(seed=134)
2826
self._a = self.R.random()
29-
self.set_random_state(seed=None)
3027

3128
def __call__(self, data):
3229
self.randomize()
3330
return data + self._a
3431

3532

36-
class TestRandLambdad(NumpyImageTestCase2D):
33+
class TestRandLambdad(unittest.TestCase):
3734
def test_rand_lambdad_identity(self):
38-
img = self.imt
35+
img = np.zeros((10, 10))
3936
data = {"img": img, "prop": 1.0}
4037

4138
test_func = RandTest()
42-
39+
test_func.set_random_state(seed=134)
4340
expected = {"img": test_func(data["img"]), "prop": 1.0}
41+
test_func.set_random_state(seed=134)
4442
ret = RandLambdad(keys=["img", "prop"], func=test_func, overwrite=[True, False])(data)
45-
self.assertTrue(np.allclose(expected["img"], ret["img"]))
46-
self.assertTrue(np.allclose(expected["prop"], ret["prop"]))
43+
np.testing.assert_allclose(expected["img"], ret["img"])
44+
np.testing.assert_allclose(expected["prop"], ret["prop"])
4745

4846

4947
if __name__ == "__main__":

tests/test_rand_rotate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_correct_results(self, degrees, keep_size, mode, padding_mode, align_cor
5252
self.imt[0, 0], -np.rad2deg(angle), (0, 1), not keep_size, order=_order, mode=_mode, prefilter=False
5353
)
5454
expected = np.stack(expected).astype(np.float32)
55-
np.testing.assert_allclose(expected, rotated[0], rtol=1e-05)
55+
np.testing.assert_allclose(expected, rotated[0])
5656

5757

5858
class TestRandRotate3D(NumpyImageTestCase3D):

0 commit comments

Comments
 (0)