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

TestRandomDownsample.test_downsample()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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