コード例 #1
0
def test_Symbol_two_assumptions():
    x = Symbol('x', negative=0, integer=1)
    # order could vary
    s1 = "Symbol('x', integer=True, negative=False)"
    s2 = "Symbol('x', negative=False, integer=True)"
    assert srepr(x) in (s1, s2)
    assert eval(srepr(x), ENV) == x
コード例 #2
0
def test_PolyRing():
    assert srepr(ring("x", ZZ, lex)[0]) == "PolyRing((Symbol('x'),), ZZ, lex)"
    assert srepr(
        ring("x,y", QQ,
             grlex)[0]) == "PolyRing((Symbol('x'), Symbol('y')), QQ, grlex)"
    assert srepr(
        ring("x,y,z", ZZ["t"], lex)
        [0]) == "PolyRing((Symbol('x'), Symbol('y'), Symbol('z')), ZZ[t], lex)"
コード例 #3
0
def test_FracField():
    assert srepr(field("x", ZZ,
                       lex)[0]) == "FracField((Symbol('x'),), ZZ, lex)"
    assert srepr(
        field("x,y", QQ,
              grlex)[0]) == "FracField((Symbol('x'), Symbol('y')), QQ, grlex)"
    assert srepr(
        field("x,y,z", ZZ["t"], lex)[0]
    ) == "FracField((Symbol('x'), Symbol('y'), Symbol('z')), ZZ[t], lex)"
コード例 #4
0
def test_PolyElement():
    R, x, y = ring("x,y", ZZ)
    g = R.domain.dtype
    assert srepr(3 * x**2 * y +
                 1) == ("PolyElement(PolyRing((Symbol('x'), "
                        "Symbol('y')), ZZ, lex), [((2, 1), %s), "
                        "((0, 0), %s)])" % (repr(g(3)), repr(g(1))))
コード例 #5
0
def sT(expr, string):
    """
    sT := sreprTest

    Tests that srepr delivers the expected string and that
    the condition eval(srepr(expr))==expr holds.
    """
    assert srepr(expr) == string
    assert eval(string, ENV) == expr
コード例 #6
0
def test_FracElement():
    F, x, y = field("x,y", ZZ)
    g = F.domain.dtype
    assert srepr(
        (3 * x**2 * y + 1) /
        (x - y**2)) == ("FracElement(FracField((Symbol('x'), "
                        "Symbol('y')), ZZ, lex), [((2, 1), %s), "
                        "((0, 0), %s)], [((1, 0), %s), "
                        "((0, 2), %s)])" %
                        (repr(g(3)), repr(g(1)), repr(g(1)), repr(g(-1))))
コード例 #7
0
def test_Add():
    sT(x + y, "Add(Symbol('x'), Symbol('y'))")
    assert srepr(
        x**2 + 1,
        order='lex') == "Add(Pow(Symbol('x'), Integer(2)), Integer(1))"
コード例 #8
0
def test_printmethod():
    class R(Abs):
        def _diofantrepr(self, printer):
            return "foo(%s)" % printer._print(self.args[0])

    assert srepr(R(x)) == "foo(Symbol('x'))"
コード例 #9
0
def test_BooleanAtom():
    assert srepr(true) == "true"
    assert srepr(false) == "false"
コード例 #10
0
def test_settins():
    pytest.raises(TypeError, lambda: srepr(x, method="garbage"))
コード例 #11
0
def test_Dummy_from_Symbol():
    # should not get the full dictionary of assumptions
    n = Symbol('n', integer=True)
    d = n.as_dummy()
    assert srepr(d) == "Dummy('n', integer=True)"
コード例 #12
0
def test_Dummy():
    # cannot use sT here
    d = Dummy('d', nonzero=True)
    assert srepr(d) == "Dummy('d', nonzero=True)"
コード例 #13
0
def test_S_srepr_is_identity():
    p = Piecewise((10, Eq(x, 0)), (12, True))
    q = sympify(srepr(p))
    assert p == q