Skip to content

Commit

Permalink
Merge branch 'main' into impl3
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMelt authored Jul 10, 2024
2 parents 8895c93 + c947660 commit 189b9d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ In this course, we assume familiarity with the following Git commands and GitHub
If these are new to you then please join the
[*Introduction to Git and GitHub for Beginners* course][1], which is running in parallel.

## Accompanying slides

Please click
[here](https://hackmd.io/@jwallwork/2024-07-10-intermediate-git-tools?type=slide#/)
to access to the accompanying slides.

## The example code

This repository contains example code in a Python module `maths.py`. This module
Expand Down
3 changes: 3 additions & 0 deletions maths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sympy import Line, Point2D
import numpy as np


def equation_of_line(a, b):
Expand All @@ -9,6 +10,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}.")
line = Line(Point2D(a), Point2D(b))

def evaluate(x, y):
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 189b9d3

Please sign in to comment.