Completed
Pull Request — master (#401)
by Fernando
20:26 queued 20:26
created

tests.transforms.preprocessing.test_ensure_shape_multiple   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A TestEnsureShapeMultiple.test_2d() 0 7 1
A TestEnsureShapeMultiple.test_bad_method() 0 3 2
A TestEnsureShapeMultiple.test_crop() 0 6 1
A TestEnsureShapeMultiple.test_pad() 0 6 1
1
import torchio as tio
2
from ...utils import TorchioTestCase
3
4
5
class TestEnsureShapeMultiple(TorchioTestCase):
6
7
    def test_bad_method(self):
8
        with self.assertRaises(ValueError):
9
            tio.EnsureShapeMultiple(1, method='bad')
10
11
    def test_pad(self):
12
        sample_t1 = self.sample_subject.t1
13
        assert sample_t1.shape == (1, 10, 20, 30)
14
        transform = tio.EnsureShapeMultiple(4, method='pad')
15
        transformed = transform(sample_t1)
16
        assert transformed.shape == (1, 12, 20, 32)
17
18
    def test_crop(self):
19
        sample_t1 = self.sample_subject.t1
20
        assert sample_t1.shape == (1, 10, 20, 30)
21
        transform = tio.EnsureShapeMultiple(4, method='crop')
22
        transformed = transform(sample_t1)
23
        assert transformed.shape == (1, 8, 20, 28)
24
25
    def test_2d(self):
26
        sample_t1 = self.sample_subject.t1
27
        sample_2d = sample_t1.data[..., :1]
28
        assert sample_2d.shape == (1, 10, 20, 1)
29
        transform = tio.EnsureShapeMultiple(4, method='crop')
30
        transformed = transform(sample_2d)
31
        assert transformed.shape == (1, 8, 20, 1)
32