def _test_add():
    (x, y, a, b, c) = map(Symbol, 'xyabc')
    (p, q, r) = map(Symbol, 'pqr')
    e = (a + b)
    assert (e.match((p + b), p) == {p: a})
    assert (e.match((p + a), p) == {p: b})
    e = (1 + b)
    assert (e.match((p + b), p) == {p: 1})
    e = ((a + b) + c)
    assert (e.match(((a + p) + c), p) == {p: b})
    assert (e.match(((b + p) + c), p) == {p: a})
    e = (((a + b) + c) + x)
    assert (e.match((((a + p) + x) + c), p) == {p: b})
    assert (e.match((((b + p) + c) + x), p) == {p: a})
    assert (e.match(b) == None)
    assert (e.match((b + p), p) == {p: ((a + c) + x)})
    assert (e.match(((a + p) + c), p) == {p: (b + x)})
    assert (e.match(((b + p) + c), p) == {p: (a + x)})
    e = ((4 * x) + 5)
    assert (e.match(((3 * x) + p), p) == {p: (x + 5)})
    assert (e.match(((4 * x) + p), (p, (lambda expr: (not expr.args)))) == {p: 5})
    assert (e.match(((p * x) + 5), (p, (lambda expr: (not expr.args)))) == {p: 4})
    assert (e.match(((p * x) + q), (p, (lambda expr: (not expr.args))), (q, (lambda expr: (not expr.args)))) == {p: 4, q: 5})
    e = (((4 * x) + (5 * y)) + 6)
    assert (e.match((((p * x) + (q * y)) + r), (p, (lambda expr: (not expr.args))), (q, (lambda expr: (not expr.args))), (r, (lambda expr: (not expr.args)))) == {p: 4, q: 5, r: 6})
def _test_add():
    (x, y, a, b, c) = map(Symbol, 'xyabc')
    (p, q, r) = map(Symbol, 'pqr')
    e = (a + b)
    assert (e.match((p + b), p) == {p: a})
    assert (e.match((p + a), p) == {p: b})
    e = (1 + b)
    assert (e.match((p + b), p) == {p: 1})
    e = ((a + b) + c)
    assert (e.match(((a + p) + c), p) == {p: b})
    assert (e.match(((b + p) + c), p) == {p: a})
    e = (((a + b) + c) + x)
    assert (e.match((((a + p) + x) + c), p) == {p: b})
    assert (e.match((((b + p) + c) + x), p) == {p: a})
    assert (e.match(b) == None)
    assert (e.match((b + p), p) == {p: ((a + c) + x)})
    assert (e.match(((a + p) + c), p) == {p: (b + x)})
    assert (e.match(((b + p) + c), p) == {p: (a + x)})
    e = ((4 * x) + 5)
    assert (e.match(((3 * x) + p), p) == {p: (x + 5)})
    assert (e.match(((4 * x) + p), (p, (lambda expr: (not expr.args)))) == {p: 5})
    assert (e.match(((p * x) + 5), (p, (lambda expr: (not expr.args)))) == {p: 4})
    assert (e.match(((p * x) + q), (p, (lambda expr: (not expr.args))), (q, (lambda expr: (not expr.args)))) == {p: 4, q: 5})
    e = (((4 * x) + (5 * y)) + 6)
    assert (e.match((((p * x) + (q * y)) + r), (p, (lambda expr: (not expr.args))), (q, (lambda expr: (not expr.args))), (r, (lambda expr: (not expr.args)))) == {p: 4, q: 5, r: 6})