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

TestOneOf.test_one_of()   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
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