Deduplicate euclidean_length method in Vector (#5658)

* Rewrite parts of Vector and Matrix methods

* Refactor determinant method and add unit tests

Refactor determinant method to create separate minor and cofactor
methods.
Add respective unit tests for new methods.
Rename methods using snake case to follow Python naming conventions.

* Reorganize Vector and Matrix methods

* Update linear_algebra/README.md

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Fix punctuation and wording

* Apply suggestions from code review

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Deduplicate euclidean length method for Vector

* Add more unit tests for Euclidean length method

* Fix bug in unit test for euclidean_length

* Remove old comments for magnitude method

Co-authored-by: John Law <johnlaw.po@gmail.com>
This commit is contained in:
Tianyi Zheng
2021-10-31 14:16:02 +00:00
committed by GitHub
parent 508589e3fc
commit a64c9f1e7c
2 changed files with 23 additions and 18 deletions

View File

@ -42,12 +42,18 @@ class Test(unittest.TestCase):
x = Vector([1, 2, 3, 4])
self.assertEqual(len(x), 4)
def test_euclidLength(self) -> None:
def test_euclidean_length(self) -> None:
"""
test for method euclidean_length()
"""
x = Vector([1, 2])
y = Vector([1, 2, 3, 4, 5])
z = Vector([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
w = Vector([1, -1, 1, -1, 2, -3, 4, -5])
self.assertAlmostEqual(x.euclidean_length(), 2.236, 3)
self.assertAlmostEqual(y.euclidean_length(), 7.416, 3)
self.assertEqual(z.euclidean_length(), 0)
self.assertAlmostEqual(w.euclidean_length(), 7.616, 3)
def test_add(self) -> None:
"""