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

tests.transforms.augmentation.test_random_motion   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 17

9 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomMotion.test_negative_translation() 0 3 2
A TestRandomMotion.test_wrong_image_interpolation_type() 0 3 2
A TestRandomMotion.test_wrong_translation_type() 0 3 2
A TestRandomMotion.test_bad_num_transforms_value() 0 3 2
A TestRandomMotion.test_wrong_degrees_type() 0 3 2
A TestRandomMotion.test_with_movement() 0 7 2
A TestRandomMotion.test_wrong_image_interpolation_value() 0 3 2
A TestRandomMotion.test_no_movement() 0 8 1
A TestRandomMotion.test_negative_degrees() 0 3 2
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