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

tests.transforms.augmentation.test_random_ghosting   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 51
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 26

14 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomGhosting.test_with_ghosting() 0 5 2
A TestRandomGhosting.test_with_zero_ghost() 0 4 1
A TestRandomGhosting.test_wrong_axes_type() 0 3 2
A TestRandomGhosting.test_out_of_range_restore() 0 3 2
A TestRandomGhosting.test_wrong_intensity_type() 0 3 2
A TestRandomGhosting.test_negative_num_ghosts() 0 3 2
A TestRandomGhosting.test_out_of_range_axis_in_tuple() 0 3 2
A TestRandomGhosting.test_not_integer_num_ghosts() 0 3 2
A TestRandomGhosting.test_intensity_range_with_negative_min() 0 3 2
A TestRandomGhosting.test_out_of_range_axis() 0 3 2
A TestRandomGhosting.test_num_ghosts_range_with_negative_min() 0 3 2
A TestRandomGhosting.test_wrong_restore_type() 0 3 2
A TestRandomGhosting.test_with_zero_intensity() 0 4 1
A TestRandomGhosting.test_wrong_num_ghosts_type() 0 3 2
1
from torchio import RandomGhosting
2
from ...utils import TorchioTestCase
3
from numpy.testing import assert_array_equal
4
5
6
class TestRandomGhosting(TorchioTestCase):
7
    """Tests for `RandomGhosting`."""
8
    def test_with_zero_intensity(self):
9
        transform = RandomGhosting(intensity=0)
10
        transformed = transform(self.sample)
11
        assert_array_equal(self.sample.t1.data, transformed.t1.data)
12
13
    def test_with_zero_ghost(self):
14
        transform = RandomGhosting(num_ghosts=0)
15
        transformed = transform(self.sample)
16
        assert_array_equal(self.sample.t1.data, transformed.t1.data)
17
18
    def test_with_ghosting(self):
19
        transform = RandomGhosting()
20
        transformed = transform(self.sample)
21
        with self.assertRaises(AssertionError):
22
            assert_array_equal(self.sample.t1.data, transformed.t1.data)
23
24
    def test_intensity_range_with_negative_min(self):
25
        with self.assertRaises(ValueError):
26
            RandomGhosting(intensity=(-0.5, 4))
27
28
    def test_wrong_intensity_type(self):
29
        with self.assertRaises(ValueError):
30
            RandomGhosting(intensity='wrong')
31
32
    def test_negative_num_ghosts(self):
33
        with self.assertRaises(ValueError):
34
            RandomGhosting(num_ghosts=-1)
35
36
    def test_num_ghosts_range_with_negative_min(self):
37
        with self.assertRaises(ValueError):
38
            RandomGhosting(num_ghosts=(-1, 4))
39
40
    def test_not_integer_num_ghosts(self):
41
        with self.assertRaises(ValueError):
42
            RandomGhosting(num_ghosts=(0.7, 4))
43
44
    def test_wrong_num_ghosts_type(self):
45
        with self.assertRaises(ValueError):
46
            RandomGhosting(num_ghosts='wrong')
47
48
    def test_out_of_range_axis(self):
49
        with self.assertRaises(ValueError):
50
            RandomGhosting(axes=3)
51
52
    def test_out_of_range_axis_in_tuple(self):
53
        with self.assertRaises(ValueError):
54
            RandomGhosting(axes=(0, -1, 2))
55
56
    def test_wrong_axes_type(self):
57
        with self.assertRaises(ValueError):
58
            RandomGhosting(axes='wrong')
59
60
    def test_out_of_range_restore(self):
61
        with self.assertRaises(ValueError):
62
            RandomGhosting(restore=-1.)
63
64
    def test_wrong_restore_type(self):
65
        with self.assertRaises(TypeError):
66
            RandomGhosting(restore='wrong')
67