Skip to content

Commit fe729f9

Browse files
kshitij-mathsndem0
authored andcommitted
test: add unit tests for fit_to_points
1 parent 5c8a3b1 commit fe729f9

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/test_ffd.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,39 @@ def test_ffd_sphere_mod(self):
382382
'tests/test_datasets/meshpoints_sphere_mod.npy')
383383
mesh_points_test = ffd(mesh_points)
384384
np.testing.assert_array_almost_equal(mesh_points_test, mesh_points_ref)
385+
386+
def test_fit_to_points_default_padding(self):
387+
params = FFD()
388+
points = np.array([[0., 0., 0.], [10., 10., 10.]])
389+
params.fit_to_points(points)
390+
391+
expected_length = np.array([11., 11., 11.])
392+
expected_origin = np.array([-0.5, -0.5, -0.5])
393+
394+
np.testing.assert_array_almost_equal(params.box_length, expected_length)
395+
np.testing.assert_array_almost_equal(params.box_origin, expected_origin)
396+
397+
def test_fit_to_points_custom_padding(self):
398+
params = FFD()
399+
points = np.array([[-5., 2., 0.], [5., 6., 10.]])
400+
# Test with 10% padding
401+
params.fit_to_points(points, padding_factor=0.1)
402+
403+
expected_length = np.array([12., 4.8, 12.])
404+
expected_origin = np.array([-6., 1.6, -1.])
405+
406+
np.testing.assert_array_almost_equal(params.box_length, expected_length)
407+
np.testing.assert_array_almost_equal(params.box_origin, expected_origin)
408+
409+
def test_fit_to_points_zero_padding(self):
410+
params = FFD()
411+
points = np.array([[1., 1., 1.], [3., 4., 5.]])
412+
413+
# Test with exactly bounding the points (0% padding)
414+
params.fit_to_points(points, padding_factor=0.0)
415+
416+
expected_length = np.array([2., 3., 4.])
417+
expected_origin = np.array([1., 1., 1.])
418+
419+
np.testing.assert_array_almost_equal(params.box_length, expected_length)
420+
np.testing.assert_array_almost_equal(params.box_origin, expected_origin)

0 commit comments

Comments
 (0)