Ejemplo n.º 1
0
def test_basic_math(qtbot):
    widget = ExprEdit(text='2*cos(pi) + 20/5')
    show(locals())
    assert widget.getSymbols() == dict()
    assert widget.getExpr() == 2
    assert widget.getValue() == 2

    widget = ExprEdit(text='2*cos(pi) + pi')
    show(locals())
    assert widget.getSymbols() == dict()
    assert widget.getExpr() == parseExpr('-2 + pi')
    assert widget.getExpr() != parseExpr('-2 + pi').evalf()
    assert widget.getValue() == parseExpr('-2 + pi').evalf()
Ejemplo n.º 2
0
def test_constructor_text(qtbot):
    widget = ExprEdit(text='text')
    show(locals())
    assert bool(widget.getError()) is False
    assert getCurrentColor(
        widget, 'Background').names[0] == widget.defaultColors['default'][0]
    assert list(widget.getSymbols().values()) == [Symbol('text')]
Ejemplo n.º 3
0
def test_constructor(qtbot):
    widget = ExprEdit()
    show(locals())
    assert widget.getError() is None
    assert getCurrentColor(
        widget, 'Background').names[0] == widget.defaultColors['blank'][0]
    assert dict() == widget.getSymbols()
Ejemplo n.º 4
0
def test_constructor_symbols(qtbot):
    widget = ExprEdit(text='word')
    show(locals())
    syms = widget.getSymbols()
    assert set(syms.keys()) == {'word'}
    assert widget.getExpr().subs({'word': 3}) == 3

    # 'var' is a function somewhere in sympy
    widget.setText('word * 2**var')
    assert bool(widget.getError()) is True

    # but 'vars' is not
    widget.setText('sin(word) * 2**vars')
    assert widget.getError() is False

    widget.setText('sin(word)*(2**expon)')
    assert widget.getError() is False

    assert set(widget.getSymbols().keys()) == {'word', 'expon'}
    assert widget.getExpr().subs({'word': parseExpr('pi/2'), 'expon': 3}) == 8
Ejemplo n.º 5
0
def test_constructor_math(qtbot):
    widget = ExprEdit(text='2*a_1 + b')
    show(locals())
    syms = widget.getSymbols()
    assert set(syms.keys()) == {'a_1', 'b'}
    assert widget.getExpr().subs({'a_1': 3, 'b': 2}) == 8