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

tests.data.inference.test_grid_sampler   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

4 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_single_location() 0 4 1
A TestGridSampler.test_locations() 0 12 1
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), (1, 2, 3))
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_single_location(self):
32
        sampler = GridSampler(self.sample, (10, 20, 30), 0)
33
        fixture = [[0, 0, 0, 10, 20, 30]]
34
        self.assertEqual(sampler.locations.tolist(), fixture)
35