Skip to content

Commit

Permalink
Merge pull request #13 from Cambridge-ICCS/check_points_differ
Browse files Browse the repository at this point in the history
Check points passed to `equation_of_line` differ
  • Loading branch information
TomMelt authored Jul 10, 2024
2 parents 059a087 + a92866d commit c947660
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions maths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import numpy as np


def equation_of_line(a, b):
"""
Determine the equation of the line passing through two points.
Expand All @@ -6,6 +9,8 @@ def equation_of_line(a, b):
:arg b: the second point the line passes through
:return: function of two variables defining the line
"""
if np.allclose(a, b):
raise ValueError("Cannot determine a unique line through {a} and {b}.")
x0, y0 = a
x1, y1 = b

Expand Down
5 changes: 5 additions & 0 deletions test_maths.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ def test_equation(a, b, condition):
iszero = np.isclose(f(x, y), 0)
if (not iszero if condition(x, y) else iszero):
raise AssertionError(f"f({x},{y}) {'!=' if condition(x, y) else '=='} 0")


def test_single_point():
with pytest.raises(ValueError):
equation_of_line((0, 0), (0, 0))

0 comments on commit c947660

Please sign in to comment.