Passed
Pull Request — master (#533)
by Fernando
01:23
created

tests.transforms.preprocessing.test_keep_largest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A TestKeepLargestComponent.test_multichannel() 0 4 2
A TestKeepLargestComponent.test_one_hot() 0 5 1
1
import torch
2
import torchio as tio
3
from ...utils import TorchioTestCase
4
5
6
class TestKeepLargestComponent(TorchioTestCase):
7
    """Tests for `KeepLargestComponent`."""
8
    def test_one_hot(self):
9
        tensor = torch.as_tensor([1, 0, 1, 1, 0, 1]).reshape(1, 1, 1, 6)
10
        label_map = tio.LabelMap(tensor=tensor)
11
        largest = tio.KeepLargestComponent()(label_map)
12
        assert largest.data.sum() == 2
13
14
    def test_multichannel(self):
15
        label_map = tio.LabelMap(tensor=torch.rand(2, 3, 3, 3) > 1)
16
        with self.assertRaises(RuntimeError):
17
            tio.KeepLargestComponent()(label_map)
18