(self, tr: RandLambda, img, img_orig_type, out, expected=None)
| 38 | |
| 39 | class TestRandLambda(unittest.TestCase): |
| 40 | def check(self, tr: RandLambda, img, img_orig_type, out, expected=None): |
| 41 | # input shouldn't change |
| 42 | self.assertIsInstance(img, img_orig_type) |
| 43 | if isinstance(img, MetaTensor): |
| 44 | self.assertEqual(len(img.applied_operations), 0) |
| 45 | # output data matches expected |
| 46 | assert_allclose(expected, out, type_test=False) |
| 47 | # output type is MetaTensor with 1 appended operation |
| 48 | self.assertIsInstance(out, MetaTensor) |
| 49 | self.assertEqual(len(out.applied_operations), 1) |
| 50 | |
| 51 | # inverse |
| 52 | inv = tr.inverse(out) |
| 53 | # after inverse, input image remains unchanged |
| 54 | self.assertIsInstance(img, img_orig_type) |
| 55 | if isinstance(img, MetaTensor): |
| 56 | self.assertEqual(len(img.applied_operations), 0) |
| 57 | # after inverse, output is MetaTensor with 0 applied operations |
| 58 | self.assertIsInstance(inv, MetaTensor) |
| 59 | self.assertEqual(len(inv.applied_operations), 0) |
| 60 | |
| 61 | @parameterized.expand([[p] for p in TEST_NDARRAYS]) |
| 62 | def test_rand_lambdad_identity(self, t): |
no test coverage detected