(self)
| 143 | |
| 144 | class TestContour(unittest.TestCase): |
| 145 | def test_contour(self): |
| 146 | input_param = {"kernel_type": "Laplace"} |
| 147 | |
| 148 | for p in TEST_NDARRAYS: |
| 149 | # check 5-dim input data |
| 150 | test_cube, expected_output = gen_fixed_cube(p) |
| 151 | for cube in test_cube: |
| 152 | test_result_cube = LabelToContour(**input_param)(cube) |
| 153 | self.assertEqual(test_result_cube.shape, cube.shape) |
| 154 | |
| 155 | channels = cube.shape[0] |
| 156 | for channel in range(channels): |
| 157 | assert_allclose(test_result_cube[channel, ...], expected_output, type_test="tensor") |
| 158 | |
| 159 | # check 4-dim input data |
| 160 | test_img, expected_output = gen_fixed_img(p) |
| 161 | for img in test_img: |
| 162 | channels = img.shape[0] |
| 163 | test_result_img = LabelToContour(**input_param)(img) |
| 164 | self.assertEqual(test_result_img.shape, img.shape) |
| 165 | |
| 166 | for channel in range(channels): |
| 167 | assert_allclose(test_result_img[channel, ...], expected_output, type_test="tensor") |
| 168 | |
| 169 | # check invalid input data |
| 170 | error_input = torch.rand(1, 2) |
| 171 | self.assertRaises(ValueError, LabelToContour(**input_param), error_input) |
| 172 | error_input = torch.rand(1, 2, 3, 4, 5) |
| 173 | self.assertRaises(ValueError, LabelToContour(**input_param), error_input) |
| 174 | error_input = np.random.rand(1, 2, 3, 4, 5) |
| 175 | self.assertRaises(ValueError, LabelToContour(**input_param), error_input) |
| 176 | |
| 177 | |
| 178 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected