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
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)"
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)"
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))))
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
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))))
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))"
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'))"
def test_BooleanAtom(): assert srepr(true) == "true" assert srepr(false) == "false"
def test_settins(): pytest.raises(TypeError, lambda: srepr(x, method="garbage"))
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)"
def test_Dummy(): # cannot use sT here d = Dummy('d', nonzero=True) assert srepr(d) == "Dummy('d', nonzero=True)"
def test_S_srepr_is_identity(): p = Piecewise((10, Eq(x, 0)), (12, True)) q = sympify(srepr(p)) assert p == q