The print ordering of Add has been improved.
[sympy.git] / sympy / core / tests / test_str.py
blob6d4ac2c47efc4bbb0202972942028f43484a76e6
1 from sympy import Symbol, Rational, Derivative, I, log, sqrt, exp, sin
3 x = Symbol('x')
4 y = Symbol('y')
5 z = Symbol('z')
6 w = Symbol('w')
9 def test_pow():
10 assert str(1/x) == "1/x"
12 def test_poly_str():
13 #if any of these tests fails, it can still be correct, just the terms can
14 #be in a different order. That happens for example when we change the
15 #hash algorithm. If it is correct, just add another item in the list [] of
16 #correct results.
17 assert str((2*x-(7*x**2 - 2) + 3*y)) in ["2 - 7*x**2 + 2*x + 3*y",
18 "2 + 3*y + 2*x - 7*x**2", "2 + 3*y - 7*x**2 + 2*x",
19 "3*y + 2*x + 2 - 7*x**2", "2 + 2*x + 3*y - 7*x**2"]
20 assert str(x-y) in ["x - y", "-y + x"]
21 assert str(2+-x) in ["2 - x", "-x + 2"]
22 assert str(x-2) in ["x - 2", "(-2) + x", "-2 + x"]
23 assert str(x-y-z-w) in ["x - y - z - w","-w - y - z + x","x - w - y - z",
24 "-w + x - y - z","-z - w - y + x","-y + x - w - z",
25 "-y - z - w + x"]
26 assert str(x-y-z-w) in [
27 "-w - y - z + x","x - w - y - z","-w + x - z - y","-y - w - z + x",
28 "-y + x - z - w","-y + x - w - z","-w + x - y - z","-z - w - y +x",
29 "-y - z - w + x"]
30 assert str(x-z*y**2*z*w) in ["-z**2*y**2*w + x", "x - w*y**2*z**2",
31 "-y**2*z**2*w + x","x - w*z**2*y**2","x - y**2*z**2*w",
32 "x - y**2*w*z**2","x - z**2*y**2*w","-w*z**2*y**2 + x",
33 "-w*y**2*z**2 + x","x - z**2*w*y**2"]
35 def test_bug1():
36 assert str(x-1*y*x*y) in ["x - x*y**2", "-x*y**2 + x"]
38 def test_bug2():
39 e = x-y
40 a = str(e)
41 b = str(e)
42 assert a == b
44 def test_bug3():
45 x = Symbol("x")
46 e = sqrt(x)
47 assert str(e) == "x**(1/2)"
49 def test_bug4():
50 x = Symbol("x")
51 w = Symbol("w")
52 e = -2*sqrt(x)-w/sqrt(x)/2
53 assert str(e) not in ["(-2)*x**1/2(-1/2)*x**(-1/2)*w",
54 "-2*x**1/2(-1/2)*x**(-1/2)*w","-2*x**1/2-1/2*x**-1/2*w"]
55 assert str(e) in ["-2*x**(1/2) - 1/2*x**(-1/2)*w", "-2*x**(1/2) - 1/2*w*x**(-1/2)",
56 "-1/2*x**(-1/2)*w - 2*x**(1/2)", "-1/2*w*x**(-1/2) - 2*x**(1/2)"]
58 def test_Derivative():
59 x = Symbol("x")
60 y = Symbol("y")
62 e = Derivative(x**2, x, evaluate=False)
63 assert str(e) == "D(x**2, x)"
65 e = Derivative(x**2/y, x, y, evaluate=False)
66 assert str(e) == "D(x**2/y, x, y)"
68 def test_x_div_y():
69 x = Symbol("x")
70 y = Symbol("y")
71 assert str(x/y) == "x/y"
72 assert str(y/x) == "y/x"
74 def test_ordering():
75 x = Symbol("x")
76 assert str(sin(x).series(x, 0, 15)) == "x - 1/6*x**3 + (1/120)*x**5 - 1/5040*x**7 + (1/362880)*x**9 - 1/39916800*x**11 + (1/6227020800)*x**13 + O(x**15)"