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

tests.transforms.augmentation.test_random_downsample   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomDownsample.test_out_of_range_axis() 0 3 2
A TestRandomDownsample.test_below_one_downsampling() 0 3 2
A TestRandomDownsample.test_wrong_downsampling_type() 0 3 2
A TestRandomDownsample.test_downsample() 0 7 1
A TestRandomDownsample.test_wrong_axes_type() 0 3 2
A TestRandomDownsample.test_out_of_range_axis_in_tuple() 0 3 2
1
import numpy as np
2
from torchio.transforms import RandomDownsample
3
from ...utils import TorchioTestCase
4
5
6
class TestRandomDownsample(TorchioTestCase):
7
    """Tests for `RandomDownsample`."""
8
9
    def test_downsample(self):
10
        transform = RandomDownsample(
11
            axes=1,
12
            downsampling=(2., 2.)
13
        )
14
        transformed = transform(self.sample)
15
        self.assertEqual(self.sample.spacing[1] * 2, transformed.spacing[1])
16
17
    def test_out_of_range_axis(self):
18
        with self.assertRaises(ValueError):
19
            RandomDownsample(axes=3)
20
21
    def test_out_of_range_axis_in_tuple(self):
22
        with self.assertRaises(ValueError):
23
            RandomDownsample(axes=(0, -1, 2))
24
25
    def test_wrong_axes_type(self):
26
        with self.assertRaises(ValueError):
27
            RandomDownsample(axes='wrong')
28
29
    def test_wrong_downsampling_type(self):
30
        with self.assertRaises(ValueError):
31
            RandomDownsample(downsampling='wrong')
32
33
    def test_below_one_downsampling(self):
34
        with self.assertRaises(ValueError):
35
            RandomDownsample(downsampling=0.2)
36