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

TestGridSampler.test_large_patch()   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nop 1
dl 0
loc 3
rs 10
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
        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