Skip to content

Commit

Permalink
Fixed test issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Schaffranek committed Jul 11, 2020
1 parent 374f600 commit c6e0f6d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion fastvector/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .vector import Vector2D
from .vector import Vector2D
52 changes: 28 additions & 24 deletions fastvector/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
from math import sqrt
from functools import total_ordering

@total_ordering

@total_ordering
class Vector2D:
"""Vector2D class to perform simple vector operations.
"""

def __init__(self, x: SupportsFloat = 0, y: SupportsFloat = 0):
"""Creates a vector instance with the given x and y values.
Parameters
----------
x : number
x-Coordinate, by default 0
y : number
y-Coordinate, by default 0
Raises
------
TypeError
Expand All @@ -34,7 +36,7 @@ def __init__(self, x: SupportsFloat = 0, y: SupportsFloat = 0):

def __call__(self) -> str:
"""Callable for the vector instance to return its representation.
Returns
-------
str
Expand All @@ -45,7 +47,7 @@ def __call__(self) -> str:

def __repr__(self) -> str:
"""The vector instance representation.
Returns
-------
str
Expand All @@ -55,7 +57,7 @@ def __repr__(self) -> str:

def __str__(self) -> str:
"""The vector instance as a string.
Returns
-------
str
Expand All @@ -65,7 +67,7 @@ def __str__(self) -> str:

def __bool__(self) -> bool:
"""Returns the truth value of the vector instance.
Returns
-------
bool
Expand All @@ -76,7 +78,7 @@ def __bool__(self) -> bool:

def __abs__(self) -> float:
"""Returns the length (magnitude) of the vector instance
Returns
-------
float
Expand All @@ -86,28 +88,29 @@ def __abs__(self) -> float:

def check_vector_types(self, vector2: Vector2D):
"""Checks if the self and vector2 are an instance of the Vector2D class.
Parameters
----------
vector2 : Vector2D
Other vector (right of the operator).
Raises
------
TypeError
If self, or vector2 are not an instance of the Vector2D class.
"""
if not isinstance(self, Vector2D) or not isinstance(vector2, Vector2D):
raise TypeError('You have to pass in two instances of the vector class!')
raise TypeError(
'You have to pass in two instances of the vector class!')

def __eq__(self, other_vector: Any) -> bool:
"""Check if the vector instances have the same values.
Parameters
----------
other_vector : Vector2D
Other vector instance (right-hand-side of the operator)
Returns
-------
bool
Expand All @@ -122,12 +125,12 @@ def __eq__(self, other_vector: Any) -> bool:

def __lt__(self, other_vector: Vector2D) -> bool:
"""Check if the self instance is less than the other vector instance.
Parameters
----------
other_vector : Vector2D
Other vector instance (right-hand-side of the operator)
Returns
-------
bool
Expand All @@ -142,12 +145,12 @@ def __lt__(self, other_vector: Vector2D) -> bool:

def __add__(self, other_vector: Vector2D) -> Vector2D:
"""Returns the additon vector of the self and the other vector instance.
Parameters
----------
other_vector : Vector2D
Other vector instance (right-hand-side of the operator)
Returns
-------
Vector2D
Expand All @@ -160,12 +163,12 @@ def __add__(self, other_vector: Vector2D) -> Vector2D:

def __sub__(self, other_vector: Vector2D) -> Vector2D:
"""Returns the subtraction vector of the self and the other vector instance.
Parameters
----------
other_vector : Vector2D
Other vector instance (right-hand-side of the operator)
Returns
-------
Vector2D
Expand All @@ -178,12 +181,12 @@ def __sub__(self, other_vector: Vector2D) -> Vector2D:

def __mul__(self, other: Union[Vector2D, SupportsFloat]) -> Union[Vector2D, SupportsFloat]:
"""Returns the multiplication of the self vector and the other vector(or number) instance.
Parameters
----------
other : Vector2D or number
Other vector instance or scaler value (right-hand-side of the operator)
Returns
-------
Vector2D
Expand All @@ -194,16 +197,17 @@ def __mul__(self, other: Union[Vector2D, SupportsFloat]) -> Union[Vector2D, Supp
elif isinstance(other, numbers.Real):
return Vector2D(self.x * other, self.y * other)
else:
raise TypeError('You must pass in a vector instance or an int/float number!')
raise TypeError(
'You must pass in a vector instance or an int/float number!')

def __truediv__(self, other: SupportsFloat) -> Vector2D:
"""Returns the multiplication of the self vector and the other vector(or number) instance.
Parameters
----------
other : Vector2D or number
Other vector instance or scaler value (right-hand-side of the operator)
Returns
-------
Vector2D
Expand Down
Empty file added tests/__init__.py
Empty file.
3 changes: 2 additions & 1 deletion tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""
import unittest

from vector import Vector2D
from fastvector import Vector2D


class VectorTests(unittest.TestCase):
def setUp(self):
Expand Down

0 comments on commit c6e0f6d

Please sign in to comment.