<commit_before>from sympy import abs, Catalan, cos, Derivative, E, EulerGamma, exp, factorial,\
                  Function, GoldenRatio, I, Integer, Integral, Interval, Lambda,\
                  Limit, log, Matrix, nan, O, oo, pi, Rational, Real, Rel, S,\
                  sin, SMatrix, sqrt, sum, Sum, Sum2, Symbol, symbols, Wild,\
                  WildFunction, zeta, zoo
from sympy.core.basic import Basic
from sympy.physics.units import second
from sympy.polys.polynomial import Poly
from sympy.polys.rootfinding import RootsOf, RootOf, RootSum
from sympy.statistics.distributions import Normal, Sample, Uniform
from sympy.geometry import Point, Circle
from sympy.utilities.pytest import XFAIL

from sympy.core.basic import StrPrinter

from sympy.printing import sstr, sstrrepr

spr = StrPrinter.doprint

x, y, z, w = symbols('xyzw')
d = Symbol('d', dummy=True)

def test_printmethod():
    class R(abs):
        def _sympystr_(self, printer):
            return "foo(%s)" % printer._print(self.args[0])
    assert spr(R(x)) == "foo(x)"
    class R(abs):
        def _sympystr_(self, printer):
            return "foo"
    assert spr(R(x)) == "foo"

def test_abs():
    assert str(abs(x)) == "abs(x)"
    assert str(abs(Rational(1,6))) == "1/6"
    assert str(abs(Rational(-1,6))) == "1/6"

def test_Add():
    assert str(x+y) == "x + y"
    assert str(x+1) == "1 + x"
    assert str(x+x**2) == "x + x**2"
    assert str(5+x+y+x*y+x**2+y**2) == "5 + x + y + x*y + x**2 + y**2"
    assert str(1+x+x**2/2+x**3/3) == "1 + x + x**2/2 + x**3/3"
    assert str(2*x-7*x**2 + 2 + 3*y) == "2 + 2*x + 3*y - 7*x**2"
    assert str(x-y) == "x - y"
    assert str(2-x) == "2 - x"
    assert str(x-2) == "-2 + x"
    assert str(x-y-z-w) == "x - w - y - z"
    assert str(x-z*y**2*z*w) == "x - w*y**2*z**2"
    assert str(x-1*y*x*y) == "x - x*y**2"
    assert str(sin(x).series(x, 0, 15)) == "x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 - x**11/39916800 + x**13/6227020800 + O(x**15)"

def test_Catalan():
    assert str(Catalan) == "Catalan"

def test_ComplexInfinity():
    assert str(zoo) == "zoo"

def test_Derivative():
    assert str(Derivative(x, y)) == "D(x, y)"
    assert str(Derivative(x**2, x, evaluate=False)) == "D(x**2, x)"
    assert str(Derivative(x**2/y, x, y, evaluate=False)) == "D(x**2/y, x, y)"

def test_dict():
    assert str({1: 1+x}) == spr({1: 1+x}) == "{1: 1 + x}"
    assert str({1: x**2, 2: y*x}) in ("{1: x**2, 2: x*y}", "{2: x*y, 1: x**2}")
    assert spr({1: x**2, 2: y*x}) == "{1: x**2, 2: x*y}"

def test_Dummy():
    assert str(d) == "_d"
    assert str(d+x) == "x + _d"

def test_EulerGamma():
    assert str(EulerGamma) == "EulerGamma"

def test_Exp():
    assert str(E) == "E"

def test_Factorial():
    n = Symbol('n', integer=True)
    assert str(factorial(-2)) == "0"
    assert str(factorial(0)) == "1"
    assert str(factorial(7)) == "5040"
    assert str(factorial(n)) == "n!"
    assert str(factorial(2*n)) == "(2*n)!"

def test_Function():
    f = Function('f')
    fx = f(x)
    w = WildFunction('w')
    assert str(f) == "f"
    assert str(fx) == "f(x)"
    assert str(w) == "w_"

def test_Geometry():
    assert spr(Point(0,0))  == 'Point(0, 0)'
    assert spr(Circle(Point(0,0), 3))   == 'Circle(Point(0, 0), 3)'
    # TODO test other Geometry entities

def test_GoldenRatio():
    assert str(GoldenRatio) == "GoldenRatio"

def test_ImaginaryUnit():
    assert str(I) == "I"

def test_Infinity():
    assert str(oo) == "oo"

def test_Integer():
    assert str(Integer(-3)) == "-3"
    assert str(Integer(1)) == "1"
    assert str(Integer(0)) == "0"
    assert str(Integer(25)) == "25"

def test_Integral():
    assert str(Integral(sin(x), y)) == "Integral(sin(x), y)"
    assert str(Integral(sin(x), (y, 0, 1))) == "Integral(sin(x), (y, 0, 1))"

def test_Interval():
    a = Symbol('a', real=True)
    assert str(Interval(0, a)) == "[0, a]"
    assert str(Interval(0, a, False, False)) == "[0, a]"
    assert str(Interval(0, a, True, False)) == "(0, a]"
    assert str(Interval(0, a, False, True)) == "[0, a)"
    assert str(Interval(0, a, True, True)) == "(0, a)"

def test_Lambda():
    assert str(Lambda(d, d**2)) == "Lambda(_d, _d**2)"

def test_Limit():
    assert str(Limit(sin(x)/x, x, y)) == "Limit(sin(x)/x, x, y)"
    assert str(Limit(1/x, x, 0)) == "Limit(1/x, x, 0)"
    assert str(Limit(sin(x)/x, x, y, dir="-")) == "Limit(sin(x)/x, x, y, dir='-')"
<commit_msg>Add test for issue 1022<commit_after>from sympy import abs, Catalan, cos, Derivative, E, EulerGamma, exp, factorial,\
                  Function, GoldenRatio, I, Integer, Integral, Interval, Lambda,\
                  Limit, log, Matrix, nan, O, oo, pi, Rational, Real, Rel, S,\
                  sin, SMatrix, sqrt, sum, Sum, Sum2, Symbol, symbols, Wild,\
                  WildFunction, zeta, zoo
from sympy.core.basic import Basic
from sympy.physics.units import second
from sympy.polys.polynomial import Poly
from sympy.polys.rootfinding import RootsOf, RootOf, RootSum
from sympy.statistics.distributions import Normal, Sample, Uniform
from sympy.geometry import Point, Circle
from sympy.utilities.pytest import XFAIL

from sympy.core.basic import StrPrinter

from sympy.printing import sstr, sstrrepr

spr = StrPrinter.doprint

x, y, z, w = symbols('xyzw')
d = Symbol('d', dummy=True)

def test_printmethod():
    class R(abs):
        def _sympystr_(self, printer):
            return "foo(%s)" % printer._print(self.args[0])
    assert spr(R(x)) == "foo(x)"
    class R(abs):
        def _sympystr_(self, printer):
            return "foo"
    assert spr(R(x)) == "foo"

def test_abs():
    assert str(abs(x)) == "abs(x)"
    assert str(abs(Rational(1,6))) == "1/6"
    assert str(abs(Rational(-1,6))) == "1/6"

def test_Add():
    assert str(x+y) == "x + y"
    assert str(x+1) == "1 + x"
    assert str(x+x**2) == "x + x**2"
    assert str(5+x+y+x*y+x**2+y**2) == "5 + x + y + x*y + x**2 + y**2"
    assert str(1+x+x**2/2+x**3/3) == "1 + x + x**2/2 + x**3/3"
    assert str(2*x-7*x**2 + 2 + 3*y) == "2 + 2*x + 3*y - 7*x**2"
    assert str(x-y) == "x - y"
    assert str(2-x) == "2 - x"
    assert str(x-2) == "-2 + x"
    assert str(x-y-z-w) == "x - w - y - z"
    assert str(x-z*y**2*z*w) == "x - w*y**2*z**2"
    assert str(x-1*y*x*y) == "x - x*y**2"
    assert str(sin(x).series(x, 0, 15)) == "x - x**3/6 + x**5/120 - x**7/5040 + x**9/362880 - x**11/39916800 + x**13/6227020800 + O(x**15)"

def test_Catalan():
    assert str(Catalan) == "Catalan"

def test_ComplexInfinity():
    assert str(zoo) == "zoo"

def test_Derivative():
    assert str(Derivative(x, y)) == "D(x, y)"
    assert str(Derivative(x**2, x, evaluate=False)) == "D(x**2, x)"
    assert str(Derivative(x**2/y, x, y, evaluate=False)) == "D(x**2/y, x, y)"

def test_dict():
    assert str({1: 1+x}) == spr({1: 1+x}) == "{1: 1 + x}"
    assert str({1: x**2, 2: y*x}) in ("{1: x**2, 2: x*y}", "{2: x*y, 1: x**2}")
    assert spr({1: x**2, 2: y*x}) == "{1: x**2, 2: x*y}"

def test_Dummy():
    assert str(d) == "_d"
    assert str(d+x) == "x + _d"

def test_EulerGamma():
    assert str(EulerGamma) == "EulerGamma"

def test_Exp():
    assert str(E) == "E"

def test_Factorial():
    n = Symbol('n', integer=True)
    assert str(factorial(-2)) == "0"
    assert str(factorial(0)) == "1"
    assert str(factorial(7)) == "5040"
    assert str(factorial(n)) == "n!"
    assert str(factorial(2*n)) == "(2*n)!"

def test_Function():
    f = Function('f')
    fx = f(x)
    w = WildFunction('w')
    assert str(f) == "f"
    assert str(fx) == "f(x)"
    assert str(w) == "w_"

def test_Geometry():
    assert spr(Point(0,0))  == 'Point(0, 0)'
    assert spr(Circle(Point(0,0), 3))   == 'Circle(Point(0, 0), 3)'
    # TODO test other Geometry entities

def test_GoldenRatio():
    assert str(GoldenRatio) == "GoldenRatio"

def test_ImaginaryUnit():
    assert str(I) == "I"

def test_Infinity():
    assert str(oo) == "oo"
    assert str(I * oo) == "(oo)*I"

def test_Integer():
    assert str(Integer(-3)) == "-3"
    assert str(Integer(1)) == "1"
    assert str(Integer(0)) == "0"
    assert str(Integer(25)) == "25"

def test_Integral():
    assert str(Integral(sin(x), y)) == "Integral(sin(x), y)"
    assert str(Integral(sin(x), (y, 0, 1))) == "Integral(sin(x), (y, 0, 1))"

def test_Interval():
    a = Symbol('a', real=True)
    assert str(Interval(0, a)) == "[0, a]"
    assert str(Interval(0, a, False, False)) == "[0, a]"
    assert str(Interval(0, a, True, False)) == "(0, a]"
    assert str(Interval(0, a, False, True)) == "[0, a)"
    assert str(Interval(0, a, True, True)) == "(0, a)"

def test_Lambda():
    assert str(Lambda(d, d**2)) == "Lambda(_d, _d**2)"

def test_Limit():
    assert str(Limit(sin(x)/x, x, y)) == "Limit(sin(x)/x, x, y)"
    assert str(Limit(1/x, x, 0)) == "Limit(1/x, x, 0)"
    assert str(Limit(sin(x)/x, x, y, dir="-")) == "Limit(sin(x)/x, x, y, dir='-')"

{'fraction_non_alphanumeric': 0.2200967705637448, 'fraction_numerical': 0.03870822549791831, 'mean_word_length': 3.287506029908345, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7128339', 'n_tokens_mistral': 3781, 'n_tokens_neox': 3637, 'n_words': 914}