-
Notifications
You must be signed in to change notification settings - Fork 230
/
test_random_motion.py
56 lines (46 loc) · 1.68 KB
/
test_random_motion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from torchio import RandomMotion
from ...utils import TorchioTestCase
class TestRandomMotion(TorchioTestCase):
"""Tests for `RandomMotion`."""
def test_bad_num_transforms_value(self):
with self.assertRaises(ValueError):
RandomMotion(num_transforms=0)
def test_no_movement(self):
transform = RandomMotion(
degrees=0,
translation=0,
num_transforms=1
)
transformed = transform(self.sample_subject)
self.assertTensorAlmostEqual(
self.sample_subject.t1.data,
transformed.t1.data,
decimal=4,
)
def test_with_movement(self):
transform = RandomMotion(
num_transforms=1
)
transformed = transform(self.sample_subject)
self.assertTensorNotEqual(
self.sample_subject.t1.data,
transformed.t1.data,
)
def test_negative_degrees(self):
with self.assertRaises(ValueError):
RandomMotion(degrees=-10)
def test_wrong_degrees_type(self):
with self.assertRaises(ValueError):
RandomMotion(degrees='wrong')
def test_negative_translation(self):
with self.assertRaises(ValueError):
RandomMotion(translation=-10)
def test_wrong_translation_type(self):
with self.assertRaises(ValueError):
RandomMotion(translation='wrong')
def test_wrong_image_interpolation_type(self):
with self.assertRaises(TypeError):
RandomMotion(image_interpolation=0)
def test_wrong_image_interpolation_value(self):
with self.assertRaises(ValueError):
RandomMotion(image_interpolation='wrong')