Skip to content

Commit

Permalink
test: catch IndexError
Browse files Browse the repository at this point in the history
Add test for IndexError in get_overlapping_vertices
  • Loading branch information
Olaf Haag committed Nov 17, 2023
1 parent 2d91703 commit 8965bd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/readyplayerme/meshops/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def get_overlapping_vertices(
:param precision: Tolerance for considering positions as overlapping.
:return: A list of grouped vertices that share position.
"""
selected_vertices = vertices_pos if indices is None else vertices_pos[indices]
try:
selected_vertices = vertices_pos if indices is None else vertices_pos[indices]
except IndexError as error:
msg = "Indices must be within bounds of vertices array."
raise IndexError(msg) from error

tree = cKDTree(selected_vertices)

Expand Down
9 changes: 9 additions & 0 deletions tests/readyplayerme/meshops/unit/test_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,12 @@ def test_get_overlapping_vertices(
assert len(grouped_vertices) == len(expected), "Number of groups doesn't match expected"
for group, exp_group in zip(grouped_vertices, expected, strict=False):
assert np.array_equal(group, exp_group), f"Grouped vertices {group} do not match expected {exp_group}"


def test_get_overlapping_vertices_index_error():
"""Test the get_overlapping_vertices function with indices that are out of bounds for the vertices."""
vertices = np.array([[1.0, 1.0, 1.0], [1.0, 1.0, 1.0]])
indices = np.array([2, 3, -4])

with pytest.raises(IndexError):
mesh.get_overlapping_vertices(vertices, indices)

0 comments on commit 8965bd8

Please sign in to comment.