Passed
Push — master ( f45b7d...d17c98 )
by Fernando
01:33
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 ..utils import TorchioTestCase
4
from torchio.data import GridSampler
0 ignored issues
show
introduced by
first party import "from torchio.data import GridSampler" should be placed before "from ..utils import TorchioTestCase"
Loading history...
5
6
class TestGridSampler(TorchioTestCase):
7
    """Tests for `GridSampler`."""
8
9
    def test_locations(self):
10
        sampler = GridSampler(self.sample, (5, 20, 20), (1, 2, 3))
11
        fixture = [
12
            [0, 0, 0, 5, 20, 20],
13
            [0, 0, 10, 5, 20, 30],
14
            [0, 0, 5, 5, 20, 25],
15
            [3, 0, 0, 8, 20, 20],
16
            [3, 0, 10, 8, 20, 30],
17
            [3, 0, 5, 8, 20, 25],
18
            [5, 0, 0, 10, 20, 20],
19
            [5, 0, 10, 10, 20, 30],
20
            [5, 0, 5, 10, 20, 25],
21
        ]
22
        self.assertEqual(sampler.locations.tolist(), fixture)
23
24
    def test_large_window(self):
25
        with self.assertRaises(ValueError):
26
            GridSampler(self.sample, (5, 21, 5), (1, 2, 3))
27
28
    def test_single_location(self):
29
        sampler = GridSampler(self.sample, (10, 20, 30), 0)
30
        fixture = [[0, 0, 0, 10, 20, 30]]
31
        self.assertEqual(sampler.locations.tolist(), fixture)
32