Skip to content
Snippets Groups Projects
Commit 6bff474a authored by Markus Holzer's avatar Markus Holzer
Browse files

Added test case for LinearEquationSystem

parent b7a97729
Branches
Tags
1 merge request!168Extend testsuite
...@@ -206,6 +206,7 @@ class LinearEquationSystem: ...@@ -206,6 +206,7 @@ class LinearEquationSystem:
non_zero_rows = self.next_zero_row non_zero_rows = self.next_zero_row
num_unknowns = len(self.unknowns) num_unknowns = len(self.unknowns)
if non_zero_rows == 0: if non_zero_rows == 0:
print("test")
return 'multiple' return 'multiple'
*row_begin, left, right = self._matrix.row(non_zero_rows - 1) *row_begin, left, right = self._matrix.row(non_zero_rows - 1)
...@@ -239,8 +240,3 @@ class LinearEquationSystem: ...@@ -239,8 +240,3 @@ class LinearEquationSystem:
break break
result -= 1 result -= 1
self.next_zero_row = result self.next_zero_row = result
def find_unique_solutions_with_zeros(system: LinearEquationSystem):
if not system.solution_structure() != 'multiple':
raise ValueError("Function works only for underdetermined systems")
import sympy as sp
from pystencils.utils import LinearEquationSystem
def test_LinearEquationSystem():
x, y, z = sp.symbols("x, y, z")
les = LinearEquationSystem([x, y, z])
les.add_equation(1 * x + 2 * y - 1 * z + 4)
les.add_equation(2 * x + 1 * y + 1 * z - 2)
les.add_equation(1 * x + 2 * y + 1 * z + 2)
# usually reduce is not necessary since almost every function of LinearEquationSystem calls reduce beforehand
les.reduce()
expected_matrix = sp.Matrix([[1, 0, 0, sp.Rational(5, 3)],
[0, 1, 0, sp.Rational(-7, 3)],
[0, 0, 1, sp.Integer(1)]])
assert les.matrix == expected_matrix
assert les.rank == 3
sol = les.solution()
assert sol[x] == sp.Rational(5, 3)
assert sol[y] == sp.Rational(-7, 3)
assert sol[z] == sp.Integer(1)
les = LinearEquationSystem([x, y])
assert les.solution_structure() == 'multiple'
les.add_equation(x + 1)
assert les.solution_structure() == 'multiple'
les.add_equation(y + 2)
assert les.solution_structure() == 'single'
les.add_equation(x + y + 5)
assert les.solution_structure() == 'none'
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment