From ec85cc81915cda82cec22e6ed9a4177b6dc1103e Mon Sep 17 00:00:00 2001 From: Alex Veltman Date: Thu, 24 Oct 2019 12:39:51 +0200 Subject: [PATCH] Fixes in methods and tests in Linear Algebra (#1432) * Fixes in methods and tests * Renamed tests.py to test_linear_algebra.py * removed force_test() * Delete test_linear_algebra.py * Format code with psf/black * Rename tests.py to test_linear_algebra.py --- linear_algebra/src/lib.py | 4 ++-- .../src/{tests.py => test_linear_algebra.py} | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) rename linear_algebra/src/{tests.py => test_linear_algebra.py} (94%) diff --git a/linear_algebra/src/lib.py b/linear_algebra/src/lib.py index 2f7a17753..15d176cc6 100644 --- a/linear_algebra/src/lib.py +++ b/linear_algebra/src/lib.py @@ -119,7 +119,7 @@ class Vector(object): size = len(self) if size == len(other): result = [self.__components[i] - other.component(i) for i in range(size)] - return result + return Vector(result) else: # error case raise Exception("must have the same size") @@ -130,7 +130,7 @@ class Vector(object): """ if isinstance(other, float) or isinstance(other, int): ans = [c * other for c in self.__components] - return ans + return Vector(ans) elif isinstance(other, Vector) and (len(self) == len(other)): size = len(self) summe = 0 diff --git a/linear_algebra/src/tests.py b/linear_algebra/src/test_linear_algebra.py similarity index 94% rename from linear_algebra/src/tests.py rename to linear_algebra/src/test_linear_algebra.py index 4123a7c9e..f8e7db7de 100644 --- a/linear_algebra/src/tests.py +++ b/linear_algebra/src/test_linear_algebra.py @@ -45,7 +45,7 @@ class Test(unittest.TestCase): test for the eulidean length """ x = Vector([1, 2]) - self.assertAlmostEqual(x.eulidLength(), 2.236, 3) + self.assertAlmostEqual(x.euclidLength(), 2.236, 3) def test_add(self): """ @@ -156,13 +156,6 @@ class Test(unittest.TestCase): str(squareZeroMatrix(5)), ) -def force_test() -> None: - """ - This will ensure that pytest runs the unit tests above. - To explore https://github.com/TheAlgorithms/Python/pull/1124 uncomment the line below. - >>> # unittest.main() - """ - pass - + if __name__ == "__main__": unittest.main()