- Install depedencies:
poetry install
- Remove cache directory:
rm -r .hypothesis
- Show maths example
- Show
poetry run pytest --hypothesis-show-statistics
- Remove cache directory:
rm -r .hypothesis
- Show
poetry run pytest --hypothesis-show-statistics
Vector class copied from / inspired by Fluent Python example.
-
Show
Vector
class -
Define mathematical properties of a vector:
- Two identical vectors are equal
- Adding vectors
Vector(x1, x2, x3, ...)+Vector(y1, y2, y3, ...)
of equal length produces a new vectorVector(x1+y1, x2+y2, x3+y3, ...)
- Vector is true if any of it's components is != 0
- Vector is false if all of it's components are == 0
- Length (magnitude) of a unit vector (e.g.
(1, 0, 0, 0, ...)
) is always 1 - Length (magnitude) of a zero vector is always 0
Vector(x1, x2, x3, ...) * N
isVector(x1 * N, x2 * N, x3 * N, ...)
Vector(x1, x2, x3, ...) * Vector(y1, y2, y3, ...)
isVector(x1 * y1, x2 * y2, x3 * y3, ...)
Vector(x1, x2, x3, ...) @ Vector(y1, y2, y3, ...)
isx1*y1 + x2*y2 + x3*y3 + ...
- Slice
[:]
of a vector is equal to the vector - Slice
[x:y]
of a vector is still a vector - Slice
[n]
of a vector is a single value
-
Implement as many test cases as possible, explaining tips and tricks