ch01: automated tests
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user