Skip to content

Commit 7485861

Browse files
committed
improve test coverage
1 parent 2b3b3c5 commit 7485861

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tests/test_utils.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from burnman.utils.math import independent_row_indices
1616
from burnman.utils.math import array_to_rational_matrix
1717
from burnman.utils.math import complete_basis, generate_complete_basis
18+
from burnman.utils.plotting import visual_center_of_polygon
1819

1920

2021
class test_utils(BurnManTest):
@@ -258,6 +259,47 @@ def test_generate_complete_basis(self):
258259
c2 = generate_complete_basis(incomplete_basis, array)
259260
np.testing.assert_allclose(c, c2, rtol=1e-5)
260261

262+
def test_visual_center_square(self):
263+
square = [np.array([[0, 0], [10, 0], [10, 10], [0, 10]])]
264+
center = visual_center_of_polygon(square, precision=0.01)
265+
self.assertTrue(np.allclose(center, [5, 5], atol=0.1))
266+
267+
def test_visual_center_with_distance(self):
268+
square = [np.array([[0, 0], [10, 0], [10, 10], [0, 10]])]
269+
center, dist = visual_center_of_polygon(
270+
square, precision=0.01, with_distance=True
271+
)
272+
self.assertTrue(np.allclose(center, [5, 5], atol=0.1))
273+
self.assertTrue(abs(dist - 5.0) < 0.2)
274+
275+
def test_visual_center_narrow_rectangle(self):
276+
rect = [np.array([[0, 0], [100, 0], [100, 1], [0, 1]])]
277+
center, dist = visual_center_of_polygon(
278+
rect, precision=0.01, with_distance=True
279+
)
280+
self.assertTrue(np.allclose(center[1], 0.5, atol=0.05))
281+
self.assertTrue(dist < 1.0)
282+
283+
def test_visual_center_invalid_input_shape(self):
284+
invalid = [np.array([[1, 2, 3]])]
285+
with self.assertRaises(ValueError):
286+
visual_center_of_polygon(invalid)
287+
288+
def test_visual_center_tiny_square(self):
289+
tiny = [np.array([[0, 0], [0.001, 0], [0.001, 0.001], [0, 0.001]])]
290+
center = visual_center_of_polygon(tiny)
291+
self.assertTrue(np.allclose(center, [0.0005, 0.0005], atol=1e-4))
292+
293+
def test_visual_center_long_square(self):
294+
tiny = [np.array([[0, 0], [1, 0], [1, 0.001], [0, 0.001]])]
295+
center = visual_center_of_polygon(tiny)
296+
self.assertTrue(np.allclose(center, [0.5, 0.0005], atol=1e-4))
297+
298+
def test_visual_center_area_zero(self):
299+
tiny = [np.array([[0, 0], [0.01, 0.1], [0, 0]])]
300+
center = visual_center_of_polygon(tiny)
301+
self.assertTrue(np.allclose(center, [0.005, 0.05], atol=1e-4))
302+
261303

262304
if __name__ == "__main__":
263305
unittest.main()

0 commit comments

Comments
 (0)