Passed
Pull Request — master (#353)
by Fernando
01:16
created

tests.transforms.augmentation.test_random_anisotropy   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomAnisotropy.test_out_of_range_axis_in_tuple() 0 3 2
A TestRandomAnisotropy.test_2d_rgb() 0 3 1
A TestRandomAnisotropy.test_wrong_axes_type() 0 3 2
A TestRandomAnisotropy.test_wrong_downsampling_type() 0 3 2
A TestRandomAnisotropy.test_out_of_range_axis() 0 3 2
A TestRandomAnisotropy.test_downsample() 0 7 1
A TestRandomAnisotropy.test_below_one_downsampling() 0 3 2
1
import torch
2
from torchio import ScalarImage, RandomAnisotropy
3
from ...utils import TorchioTestCase
4
5
6
class TestRandomAnisotropy(TorchioTestCase):
7
    """Tests for `RandomAnisotropy`."""
8
9
    def test_downsample(self):
10
        transform = RandomAnisotropy(
11
            axes=1,
12
            downsampling=(2., 2.)
13
        )
14
        transformed = transform(self.sample_subject)
15
        self.assertEqual(self.sample_subject.spacing[1], transformed.spacing[1])
16
17
    def test_out_of_range_axis(self):
18
        with self.assertRaises(ValueError):
19
            RandomAnisotropy(axes=3)
20
21
    def test_out_of_range_axis_in_tuple(self):
22
        with self.assertRaises(ValueError):
23
            RandomAnisotropy(axes=(0, -1, 2))
24
25
    def test_wrong_axes_type(self):
26
        with self.assertRaises(ValueError):
27
            RandomAnisotropy(axes='wrong')
28
29
    def test_wrong_downsampling_type(self):
30
        with self.assertRaises(ValueError):
31
            RandomAnisotropy(downsampling='wrong')
32
33
    def test_below_one_downsampling(self):
34
        with self.assertRaises(ValueError):
35
            RandomAnisotropy(downsampling=0.2)
36
37
    def test_2d_rgb(self):
38
        image = ScalarImage(tensor=torch.rand(3, 4, 5, 6))
39
        RandomAnisotropy()(image)
40