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

tests.transforms.augmentation.test_random_blur   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomBlur.test_wrong_std_type() 0 3 2
A TestRandomBlur.test_negative_std() 0 3 2
A TestRandomBlur.test_std_range_with_negative_min() 0 3 2
A TestRandomBlur.test_no_blurring() 0 4 1
A TestRandomBlur.test_with_blurring() 0 4 1
A TestRandomBlur.test_parse_stds() 0 7 1
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