Passed
Pull Request — master (#175)
by Fernando
01:24
created

TestGridSampler.test_single_location()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 4
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), (1, 2, 3))
12
        fixture = [
13
            [0, 0, 0, 5, 20, 20],
14
            [0, 0, 10, 5, 20, 30],
15
            [0, 0, 5, 5, 20, 25],
16
            [3, 0, 0, 8, 20, 20],
17
            [3, 0, 10, 8, 20, 30],
18
            [3, 0, 5, 8, 20, 25],
19
            [5, 0, 0, 10, 20, 20],
20
            [5, 0, 10, 10, 20, 30],
21
            [5, 0, 5, 10, 20, 25],
22
        ]
23
        self.assertEqual(sampler.locations.tolist(), fixture)
24
25
    def test_large_window(self):
26
        with self.assertRaises(ValueError):
27
            GridSampler(self.sample, (5, 21, 5), (1, 2, 3))
28
29
    def test_single_location(self):
30
        sampler = GridSampler(self.sample, (10, 20, 30), 0)
31
        fixture = [[0, 0, 0, 10, 20, 30]]
32
        self.assertEqual(sampler.locations.tolist(), fixture)
33