-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from JvgRansika/setup-vectors
add vector.py
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |