Skip to content
Snippets Groups Projects
  • Martin Bauer's avatar
    1e02cdc7
    Separated modules into subfolders with own setup.py · 1e02cdc7
    Martin Bauer authored
    This restructuring allows for easier separation of modules into
    separate repositories later. Also, now pip install with repo url can be
    used.
    
    The setup.py files have also been updated to correctly reference each
    other. Module versions are not extracted from git state
    1e02cdc7
    History
    Separated modules into subfolders with own setup.py
    Martin Bauer authored
    This restructuring allows for easier separation of modules into
    separate repositories later. Also, now pip install with repo url can be
    used.
    
    The setup.py files have also been updated to correctly reference each
    other. Module versions are not extracted from git state
test_assignment_collection.py 1.05 KiB
import sympy as sp
from pystencils import Assignment, AssignmentCollection
from pystencils.simp.assignment_collection import SymbolGen


def test_assignment_collection():
    x, y, z, t = sp.symbols("x y z t")
    symbol_gen = SymbolGen("a")

    ac = AssignmentCollection([Assignment(z, x + y)],
                              [], subexpression_symbol_generator=symbol_gen)

    lhs = ac.add_subexpression(t)
    assert lhs == sp.Symbol("a_0")
    ac.subexpressions.append(Assignment(t, 3))
    ac.topological_sort(sort_main_assignments=False, sort_subexpressions=True)
    assert ac.subexpressions[0].lhs == t

    assert ac.new_with_inserted_subexpression(sp.Symbol("not_defined")) == ac
    ac_inserted = ac.new_with_inserted_subexpression(t)
    ac_inserted2 = ac.new_without_subexpressions({lhs})
    assert all(a == b for a, b in zip(ac_inserted.all_assignments, ac_inserted2.all_assignments))

    print(ac_inserted)
    assert ac_inserted.subexpressions[0] == Assignment(lhs, 3)

    assert 'a_0' in str(ac_inserted)
    assert '<table' in ac_inserted._repr_html_()