ch01: automated tests

This commit is contained in:
Luciano Ramalho
2019-11-20 19:46:31 -03:00
parent d5be725318
commit 64e8bdcd79
5 changed files with 64 additions and 6 deletions

View File

@@ -1,3 +1,35 @@
"""
vector2d.py: a simplistic class demonstrating some special methods
It is simplistic for didactic reasons. It lacks proper error handling,
especially in the ``__add__`` and ``__mul__`` methods.
This example is greatly expanded later in the book.
Addition::
>>> v1 = Vector(2, 4)
>>> v2 = Vector(2, 1)
>>> v1 + v2
Vector(4, 5)
Absolute value::
>>> v = Vector(3, 4)
>>> abs(v)
5.0
Scalar multiplication::
>>> v * 3
Vector(9, 12)
>>> abs(v * 3)
15.0
"""
from math import hypot
class Vector: