Passed
Push — master ( bbbeef...45400a )
by Fernando
01:13
created

tests.transforms.augmentation.test_random_gamma   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestRandomGamma.test_with_low_gamma() 0 5 1
A TestRandomGamma.test_with_high_gamma() 0 5 1
A TestRandomGamma.test_wrong_gamma_type() 0 3 2
A TestRandomGamma.test_with_non_zero_gamma() 0 4 1
A TestRandomGamma.test_with_zero_gamma() 0 4 1
1
from torchio import RandomGamma
2
from ...utils import TorchioTestCase
3
4
5
class TestRandomGamma(TorchioTestCase):
6
    """Tests for `RandomGamma`."""
7
    def test_with_zero_gamma(self):
8
        transform = RandomGamma(log_gamma=0)
9
        transformed = transform(self.sample)
10
        self.assertTensorAlmostEqual(self.sample.t1.data, transformed.t1.data)
11
12
    def test_with_non_zero_gamma(self):
13
        transform = RandomGamma(log_gamma=(0.1, 0.3))
14
        transformed = transform(self.sample)
15
        self.assertTensorNotEqual(self.sample.t1.data, transformed.t1.data)
16
17
    def test_with_high_gamma(self):
18
        transform = RandomGamma(log_gamma=(100, 100))
19
        transformed = transform(self.sample)
20
        self.assertTensorAlmostEqual(
21
            self.sample.t1.data == 1, transformed.t1.data
22
        )
23
24
    def test_with_low_gamma(self):
25
        transform = RandomGamma(log_gamma=(-100, -100))
26
        transformed = transform(self.sample)
27
        self.assertTensorAlmostEqual(
28
            self.sample.t1.data > 0, transformed.t1.data
29
        )
30
31
    def test_wrong_gamma_type(self):
32
        with self.assertRaises(ValueError):
33
            RandomGamma(log_gamma='wrong')
34