| Total Complexity | 7 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Changes | 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 |