Skip to content

Commit

Permalink
Merge pull request #15 from JvgRansika/setup-vectors
Browse files Browse the repository at this point in the history
add vector.py
  • Loading branch information
jv-ransika authored Jan 6, 2024
2 parents 280c1eb + ee873b2 commit e5a00a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pymathzone/vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Vector:
"""
Vector class representing a vector in n-dimensional space.
Attributes:
components: A tuple containing the vector's components.
Methods:
__init__(self, components): Initializes the vector with components.
__str__(self): Returns a human-readable string representation.
__add__(self, other): Adds two vectors element-wise.
__sub__(self, other): Subtracts two vectors element-wise.
__mul__(self, scalar): Multiplies the vector by a scalar.
magnitude(self): Calculates the magnitude (length) of the vector.
"""

def __init__(self, components=None):
"""
Initialize a vector with a tuple
:param components: a tuple contain vector's components.
"""
if not isinstance(components, tuple):
raise ValueError("components must be a tuple")

self.components = components
10 changes: 10 additions & 0 deletions tests/test_vector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import unittest


class TestVector(unittest.TestCase):
def test_something(self):
self.assertEqual(True, False) # add assertion here


if __name__ == '__main__':
unittest.main()

0 comments on commit e5a00a7

Please sign in to comment.