from sympy import symbols
from sympy.utilities.iterables import postorder_traversal, preorder_traversal


w,x,y,z= symbols('wxyz')

def test_postorder_traversal():
    expr = z+w*(x+y)
    expected1 = [z, w, y, x, x + y, w*(x + y), z + w*(x + y)]
    expected2 = [z, w, x, y, x + y, w*(x + y), z + w*(x + y)]
    assert list(postorder_traversal(expr)) in [expected1, expected2]


def test_preorder_traversal():
    expr = z+w*(x+y)
    expected1 = [z + w*(x + y), z, w*(x + y), w, x + y, y, x]
    expected2 = [z + w*(x + y), z, w*(x + y), w, x + y, x, y]
    assert list(preorder_traversal(expr)) in [expected1, expected2]



@@ -298,24 +298,86 @@
  w*(x + y)%5D%0A
+    expected3 = %5Bw, y, x, x + y, w*(x + y), z, z + w*(x + y)%5D%0A
     assert l
@@ -427,24 +427,35 @@
 1, expected2
+, expected3
 %5D%0A%0A%0Adef test
@@ -622,16 +622,78 @@
 , x, y%5D%0A
+    expected3 = %5Bz + w*(x + y), w*(x + y), w, x + y, y, x, z%5D%0A
     asse
@@ -750,12 +750,23 @@
 xpected2
+, expected3
 %5D%0A%0A%0A

robustify tests for postorder_traversal and preorder_traversal