Skip to content

Commit

Permalink
Add test for invalid LineCollection args
Browse files Browse the repository at this point in the history
  • Loading branch information
JCGoran committed Jul 22, 2024
1 parent 5ed4ea5 commit 8e0a11e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/data_morph/shapes/bases/line_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class LineCollection(Shape):
"""

def __init__(self, *lines: Iterable[Iterable[Number]]) -> None:
# check that lines that have the same starting and ending points raise an error
for line in lines:
start, end = line
if np.allclose(start, end):
raise ValueError(f'Line {line} has the same start and end point')
self.lines = lines
"""Iterable[Iterable[numbers.Number]]: An iterable
of two (x, y) pairs representing the endpoints of a line."""
Expand Down
8 changes: 4 additions & 4 deletions tests/shapes/bases/test_line_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def test_distance_nonzero(self, line_collection, point, expected_distance):
assert pytest.approx(line_collection.distance(*point)) == expected_distance

@pytest.mark.parametrize('line', [[(0, 0), (0, 0)], [(-1, -1), (-1, -1)]], ids=str)
def test_distance_to_small_line_magnitude(self, line_collection, line):
"""Test _distance_point_to_line() for small line magnitudes."""
distance = line_collection._distance_point_to_line((30, 50), line)
assert distance == 9999
def test_line_as_point(self, line):
"""Test LineCollection raises a ValueError for small line magnitudes."""
with pytest.raises(ValueError):
LineCollection(line)

def test_repr(self, line_collection):
"""Test that the __repr__() method is working."""
Expand Down

0 comments on commit 8e0a11e

Please sign in to comment.