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

TestRandomNoise.test_negative_std()   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
from torchio import RandomNoise
2
from ...utils import TorchioTestCase
3
from numpy.testing import assert_array_equal
4
5
6
class TestRandomNoise(TorchioTestCase):
7
    """Tests for `RandomNoise`."""
8
    def test_no_noise(self):
9
        transform = RandomNoise(mean=0., std=0.)
10
        transformed = transform(self.sample)
11
        assert_array_equal(self.sample.t1.data, transformed.t1.data)
12
13
    def test_with_noise(self):
14
        transform = RandomNoise()
15
        transformed = transform(self.sample)
16
        with self.assertRaises(AssertionError):
17
            assert_array_equal(self.sample.t1.data, transformed.t1.data)
18
19
    def test_constant_noise(self):
20
        transform = RandomNoise(mean=(5., 5.), std=0.)
21
        transformed = transform(self.sample)
22
        assert_array_equal(self.sample.t1.data + 5, transformed.t1.data)
23
24
    def test_negative_std(self):
25
        with self.assertRaises(ValueError):
26
            RandomNoise(std=-2)
27
28
    def test_std_range_with_negative_min(self):
29
        with self.assertRaises(ValueError):
30
            RandomNoise(std=(-0.5, 4))
31
32
    def test_wrong_std_type(self):
33
        with self.assertRaises(ValueError):
34
            RandomNoise(std='wrong')
35
36
    def test_wrong_mean_type(self):
37
        with self.assertRaises(ValueError):
38
            RandomNoise(mean='wrong')
39