diff options
author | Thomas Albers Raviola <thomas@thomaslabs.org> | 2024-05-28 11:23:02 +0200 |
---|---|---|
committer | Thomas Albers Raviola <thomas@thomaslabs.org> | 2024-05-28 11:23:02 +0200 |
commit | 255c2e7b7bf721296d4d4f22cb106ab3cf197e0a (patch) | |
tree | ea255bc9397e095d436d9f265037284dfcc0cc06 /test | |
parent | c24397c9d2ca50b3989de5107498666724e8c50c (diff) |
Add unit test with pytest
Diffstat (limited to 'test')
-rw-r--r-- | test/__init__.py | 0 | ||||
-rw-r--r-- | test/test_solvers.py | 32 |
2 files changed, 32 insertions, 0 deletions
diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/__init__.py diff --git a/test/test_solvers.py b/test/test_solvers.py new file mode 100644 index 0000000..e5b73d8 --- /dev/null +++ b/test/test_solvers.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +"""Contains routines to test the solvers module""" + +import numpy as np +from numpy.typing import NDArray +import solvers + +def test_elimination_3() -> None: + """Tests elimination with 3 variables.""" + aa = np.array([[2.0, 4.0, 4.0], [5.0, 4.0, 2.0], [1.0, 2.0, -1.0]], dtype=np.float_) + bb = np.array([1.0, 4.0, 2.0], dtype=np.float_) + xx_expected = np.array([0.666666666666667, 0.416666666666667, -0.5], dtype=np.float_) + xx_gauss = solvers.gaussian_eliminate(aa, bb) + assert np.allclose(xx_expected, xx_gauss) + + +def test_pivot_3() -> None: + """Tests a solution with 3 variables, where pivot is necessary.""" + aa = np.array([[2.0, 4.0, 4.0], [1.0, 2.0, -1.0], [5.0, 4.0, 2.0]]) + bb = np.array([1.0, 2.0, 4.0]) + xx_expected = np.array([0.666666666666667, 0.416666666666667, -0.5]) + xx_gauss = solvers.gaussian_eliminate(aa, bb) + assert np.allclose(xx_expected, xx_gauss) + + +def test_lindep_3() -> None: + """Tests a linearly dependent system wit three variables.""" + aa = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]) + bb = np.array([1.0, 2.0, 3.0]) + xx_expected = None + xx_gauss = solvers.gaussian_eliminate(aa, bb) + assert xx_expected == xx_gauss |