Passed
Push — master ( c291a8...879ee9 )
by Fernando
59s
created

tests.transforms.augmentation.test_oneof   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestOneOf.test_wrong_input_type() 0 3 2
A TestOneOf.test_negative_probabilities() 0 3 2
A TestOneOf.test_zero_probabilities() 0 3 2
A TestOneOf.test_not_transform() 0 3 2
A TestOneOf.test_one_of() 0 4 1
1
import torchio
2
from torchio.transforms import OneOf, RandomAffine, RandomElasticDeformation
3
from ...utils import TorchioTestCase
4
5
6
class TestOneOf(TorchioTestCase):
7
    """Tests for `OneOf`."""
8
    def test_wrong_input_type(self):
9
        with self.assertRaises(ValueError):
10
            OneOf(1)
11
12
    def test_negative_probabilities(self):
13
        with self.assertRaises(ValueError):
14
            OneOf({RandomAffine(): -1, RandomElasticDeformation(): 1})
15
16
    def test_zero_probabilities(self):
17
        with self.assertRaises(ValueError):
18
            OneOf({RandomAffine(): 0, RandomElasticDeformation(): 0})
19
20
    def test_not_transform(self):
21
        with self.assertRaises(ValueError):
22
            OneOf({RandomAffine: 1, RandomElasticDeformation: 2})
23
24
    def test_one_of(self):
25
        transform = OneOf(
26
            {RandomAffine(): 0.2, RandomElasticDeformation(): 0.8})
27
        transform(self.sample)
28