Passed
Pull Request — master (#346)
by Fernando
01:46
created

TestRandomBlur.test_parse_stds()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
from torchio import RandomBlur
2
from ...utils import TorchioTestCase
3
4
5
class TestRandomBlur(TorchioTestCase):
6
    """Tests for `RandomBlur`."""
7
    def test_no_blurring(self):
8
        transform = RandomBlur(std=0)
9
        transformed = transform(self.sample_subject)
10
        self.assertTensorAlmostEqual(self.sample_subject.t1.data, transformed.t1.data)
11
12
    def test_with_blurring(self):
13
        transform = RandomBlur(std=(1, 3))
14
        transformed = transform(self.sample_subject)
15
        self.assertTensorNotEqual(self.sample_subject.t1.data, transformed.t1.data)
16
17
    def test_negative_std(self):
18
        with self.assertRaises(ValueError):
19
            RandomBlur(std=-2)
20
21
    def test_std_range_with_negative_min(self):
22
        with self.assertRaises(ValueError):
23
            RandomBlur(std=(-0.5, 4))
24
25
    def test_wrong_std_type(self):
26
        with self.assertRaises(ValueError):
27
            RandomBlur(std='wrong')
28
29
    def test_parse_stds(self):
30
        def do_assert(transform):
31
            self.assertEqual(transform.std_ranges, 3 * (0, 1))
32
        do_assert(RandomBlur(std=1))
33
        do_assert(RandomBlur(std=(0, 1)))
34
        do_assert(RandomBlur(std=3 * (1,)))
35
        do_assert(RandomBlur(std=3 * [0, 1]))
36