| Total Complexity | 9 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | from torchio import RandomFlip |
||
| 2 | from numpy.testing import assert_array_equal |
||
| 3 | from ...utils import TorchioTestCase |
||
| 4 | |||
| 5 | |||
| 6 | class TestRandomFlip(TorchioTestCase): |
||
| 7 | """Tests for `RandomFlip`.""" |
||
| 8 | def test_2d(self): |
||
| 9 | sample = self.make_2d(self.sample) |
||
| 10 | transform = RandomFlip(axes=(1, 2), flip_probability=1) |
||
| 11 | transformed = transform(sample) |
||
| 12 | assert_array_equal( |
||
| 13 | sample.t1.data.numpy()[:, :, ::-1, ::-1], |
||
| 14 | transformed.t1.data.numpy()) |
||
| 15 | |||
| 16 | def test_out_of_range_axis(self): |
||
| 17 | with self.assertRaises(ValueError): |
||
| 18 | RandomFlip(axes=3) |
||
| 19 | |||
| 20 | def test_out_of_range_axis_in_tuple(self): |
||
| 21 | with self.assertRaises(ValueError): |
||
| 22 | RandomFlip(axes=(0, -1, 2)) |
||
| 23 | |||
| 24 | def test_wrong_axes_type(self): |
||
| 25 | with self.assertRaises(ValueError): |
||
| 26 | RandomFlip(axes=None) |
||
| 27 | |||
| 28 | def test_wrong_flip_probability_type(self): |
||
| 29 | with self.assertRaises(ValueError): |
||
| 30 | RandomFlip(flip_probability='wrong') |
||
| 31 |