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

TestRandomSwap.test_with_swap()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
from torchio import RandomSwap
2
from ...utils import TorchioTestCase
3
from numpy.testing import assert_array_equal
4
5
6
class TestRandomSwap(TorchioTestCase):
7
    """Tests for `RandomSwap`."""
8
    def test_no_swap(self):
9
        transform = RandomSwap(patch_size=5, num_iterations=0)
10
        transformed = transform(self.sample)
11
        assert_array_equal(self.sample.t1.data, transformed.t1.data)
12
13
    def test_with_swap(self):
14
        transform = RandomSwap(patch_size=5)
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_wrong_num_iterations_type(self):
20
        with self.assertRaises(TypeError):
21
            RandomSwap(num_iterations='wrong')
22
23
    def test_negative_num_iterations(self):
24
        with self.assertRaises(ValueError):
25
            RandomSwap(num_iterations=-1)
26