Passed
Push — master ( c291a8...879ee9 )
by Fernando
59s
created

TestRandomMotion.test_with_movement()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
from torchio import RandomMotion
2
from ...utils import TorchioTestCase
3
from numpy.testing import assert_array_equal
4
5
6
class TestRandomMotion(TorchioTestCase):
7
    """Tests for `RandomMotion`."""
8
    def test_bad_num_transforms_value(self):
9
        with self.assertRaises(ValueError):
10
            RandomMotion(num_transforms=0)
11
12
    def test_no_movement(self):
13
        transform = RandomMotion(
14
            degrees=0,
15
            translation=0,
16
            num_transforms=1
17
        )
18
        transformed = transform(self.sample)
19
        assert_array_equal(self.sample.t1.data, transformed.t1.data)
20
21
    def test_with_movement(self):
22
        transform = RandomMotion(
23
            num_transforms=1
24
        )
25
        transformed = transform(self.sample)
26
        with self.assertRaises(AssertionError):
27
            assert_array_equal(self.sample.t1.data, transformed.t1.data)
28
29
    def test_negative_degrees(self):
30
        with self.assertRaises(ValueError):
31
            RandomMotion(degrees=-10)
32
33
    def test_wrong_degrees_type(self):
34
        with self.assertRaises(ValueError):
35
            RandomMotion(degrees='wrong')
36
37
    def test_negative_translation(self):
38
        with self.assertRaises(ValueError):
39
            RandomMotion(translation=-10)
40
41
    def test_wrong_translation_type(self):
42
        with self.assertRaises(ValueError):
43
            RandomMotion(translation='wrong')
44
45
    def test_wrong_image_interpolation_type(self):
46
        with self.assertRaises(TypeError):
47
            RandomMotion(image_interpolation=0)
48
49
    def test_wrong_image_interpolation_value(self):
50
        with self.assertRaises(AttributeError):
51
            RandomMotion(image_interpolation='wrong')
52