Commit 7aa67902 authored by Markus Holzer's avatar Markus Holzer
Browse files

Added test case for DotDict

parent 6bff474a
...@@ -206,7 +206,6 @@ class LinearEquationSystem: ...@@ -206,7 +206,6 @@ 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)
...@@ -224,7 +223,8 @@ class LinearEquationSystem: ...@@ -224,7 +223,8 @@ class LinearEquationSystem:
return 'multiple' return 'multiple'
def solution(self): def solution(self):
"""Solves the system if it has a single solution. Returns a dictionary mapping symbol to solution value.""" """Solves the system. Under- and overdetermined systems are supported.
Returns a dictionary mapping symbol to solution value."""
return sp.solve_linear_system(self._matrix, *self.unknowns) return sp.solve_linear_system(self._matrix, *self.unknowns)
def _resize_if_necessary(self, new_rows=1): def _resize_if_necessary(self, new_rows=1):
......
import sympy as sp import sympy as sp
from pystencils.utils import LinearEquationSystem from pystencils.utils import LinearEquationSystem
from pystencils.utils import DotDict
def test_LinearEquationSystem(): def test_LinearEquationSystem():
...@@ -34,3 +35,18 @@ def test_LinearEquationSystem(): ...@@ -34,3 +35,18 @@ def test_LinearEquationSystem():
les.add_equation(x + y + 5) les.add_equation(x + y + 5)
assert les.solution_structure() == 'none' assert les.solution_structure() == 'none'
def test_DotDict():
d = {'a': {'c': 7}, 'b': 6}
t = DotDict(d)
assert t.a.c == 7
assert t.b == 6
assert len(t) == 2
delattr(t, 'b')
assert len(t) == 1
t.b = 6
assert len(t) == 2
assert t.b == 6
Markdown is supported
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