Skip to content

Commit b578edd

Browse files
committed
added some tests of commutative operations
1 parent fa22164 commit b578edd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/rewrite.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using SymbolicUtils
22

33
include("utils.jl")
44

5-
@syms a b c
5+
@syms a b c x
66

77
@testset "Equality" begin
88
@eqtest a == a
@@ -47,6 +47,20 @@ end
4747
@eqtest @rule(+(~~x,~y,~~x) => (~~x, ~y, ~~x))(term(+,6,type=Any)) == ([], 6, [])
4848
end
4949

50+
@testset "Commutative + and *" begin
51+
r1 = @rule sin(~x) + cos(~x) => ~x
52+
@test r1(sin(a)+cos(a)) === a
53+
@test r1(sin(x)+cos(x)) === x
54+
r2 = @rule (~x+~y)*(~z+~w)^(~m) => (~x, ~y, ~z, ~w, ~m)
55+
r3 = @rule (~z+~w)^(~m)*(~x+~y) => (~x, ~y, ~z, ~w, ~m)
56+
@test r2((a+b)*(x+c)^b) === (a, b, x, c, b)
57+
@test r3((a+b)*(x+c)^b) === (a, b, x, c, b)
58+
rPredicate1 = @rule ~x::(x->isa(x,Number)) + ~y => (~x, ~y)
59+
rPredicate2 = @rule ~y + ~x::(x->isa(x,Number)) => (~x, ~y)
60+
@test rPredicate1(2+x) === (2, x)
61+
@test rPredicate2(2+x) === (2, x)
62+
end
63+
5064
@testset "Slot matcher with default value" begin
5165
r_sum = @rule (~x + ~!y)^2 => ~y
5266
@test r_sum((a + b)^2) === b

0 commit comments

Comments
 (0)