Passed
Pull Request — master (#182)
by Fernando
01:34
created

TestGridSampler.test_locations()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nop 1
dl 0
loc 14
rs 9.75
c 0
b 0
f 0
1
#!/usr/bin/env python
2
3
from torchio.data import GridSampler
4
from ...utils import TorchioTestCase
5
6
7
class TestGridSampler(TorchioTestCase):
8
    """Tests for `GridSampler`."""
9
10
    def test_locations(self):
11
        patch_size = 5, 20, 20
12
        patch_overlap = 2, 4, 6
13
        sampler = GridSampler(self.sample, patch_size, patch_overlap)
14
        fixture = [
15
            [0, 0, 0, 5, 20, 20],
16
            [0, 0, 10, 5, 20, 30],
17
            [3, 0, 0, 8, 20, 20],
18
            [3, 0, 10, 8, 20, 30],
19
            [5, 0, 0, 10, 20, 20],
20
            [5, 0, 10, 10, 20, 30],
21
        ]
22
        locations = sampler.locations.tolist()
23
        self.assertEqual(locations, fixture)
24
25
    def test_large_patch(self):
26
        with self.assertRaises(ValueError):
27
            GridSampler(self.sample, (5, 21, 5), (0, 2, 0))
28
29
    def test_large_overlap(self):
30
        with self.assertRaises(ValueError):
31
            GridSampler(self.sample, (5, 20, 5), (2, 4, 6))
32
33
    def test_odd_overlap(self):
34
        with self.assertRaises(ValueError):
35
            GridSampler(self.sample, (5, 20, 5), (2, 4, 3))
36
37
    def test_single_location(self):
38
        sampler = GridSampler(self.sample, (10, 20, 30), 0)
39
        fixture = [[0, 0, 0, 10, 20, 30]]
40
        self.assertEqual(sampler.locations.tolist(), fixture)
41