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

tests.data.inference.test_grid_sampler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestGridSampler.test_large_overlap() 0 3 2
A TestGridSampler.test_large_patch() 0 3 2
A TestGridSampler.test_locations() 0 12 1
A TestGridSampler.test_single_location() 0 4 1
A TestGridSampler.test_odd_overlap() 0 3 2
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
        sampler = GridSampler(self.sample, (5, 20, 20), (2, 4, 6))
12
        fixture = [
13
            [0, 0, 0, 5, 20, 20],
14
            [0, 0, 10, 5, 20, 30],
15
            [3, 0, 0, 8, 20, 20],
16
            [3, 0, 10, 8, 20, 30],
17
            [5, 0, 0, 10, 20, 20],
18
            [5, 0, 10, 10, 20, 30],
19
        ]
20
        locations = sampler.locations.tolist()
21
        self.assertEqual(locations, fixture)
22
23
    def test_large_patch(self):
24
        with self.assertRaises(ValueError):
25
            GridSampler(self.sample, (5, 21, 5), (0, 2, 0))
26
27
    def test_large_overlap(self):
28
        with self.assertRaises(ValueError):
29
            GridSampler(self.sample, (5, 20, 5), (2, 4, 6))
30
31
    def test_odd_overlap(self):
32
        with self.assertRaises(ValueError):
33
            GridSampler(self.sample, (5, 20, 5), (2, 4, 3))
34
35
    def test_single_location(self):
36
        sampler = GridSampler(self.sample, (10, 20, 30), 0)
37
        fixture = [[0, 0, 0, 10, 20, 30]]
38
        self.assertEqual(sampler.locations.tolist(), fixture)
39