|
55 | 55 | @test r1(exp(sin(x)+cos(x))) === x
|
56 | 56 | r2 = @rule (~x+~y)*(~z+~w)^(~m) => (~x, ~y, ~z, ~w, ~m)
|
57 | 57 | r3 = @rule (~z+~w)^(~m)*(~x+~y) => (~x, ~y, ~z, ~w, ~m)
|
58 |
| - @test r2((a+b)*(x+c)^b) === (a, b, x, c, b) |
59 |
| - @test r3((a+b)*(x+c)^b) === (a, b, x, c, b) |
| 58 | + res1 = r2((a+b)*(x+c)^b) |
| 59 | + @test issetequal(res1[1:2], [a, b]) |
| 60 | + @test issetequal(res1[3:4], [x, c]) |
| 61 | + @test isequal(res1[5], b) |
| 62 | + res2 = r3((a+b)*(x+c)^b) |
| 63 | + @test issetequal(res2[1:2], [a, b]) |
| 64 | + @test issetequal(res2[3:4], [x, c]) |
| 65 | + @test isequal(res2[5], b) |
60 | 66 | rPredicate1 = @rule ~x::(x->isa(x,Number)) + ~y => (~x, ~y)
|
61 | 67 | rPredicate2 = @rule ~y + ~x::(x->isa(x,Number)) => (~x, ~y)
|
62 | 68 | @test rPredicate1(2+x) === (2, x)
|
63 | 69 | @test rPredicate2(2+x) === (2, x)
|
64 | 70 | r5 = @rule (~y*(~z+~w))+~x => (~x, ~y, ~z, ~w)
|
65 | 71 | r6 = @rule ~x+((~z+~w)*~y) => (~x, ~y, ~z, ~w)
|
66 |
| - @test r5(c*(a+b)+d) === (d, c, a, b) |
67 |
| - @test r6(c*(a+b)+d) === (d, c, a, b) |
| 72 | + res3 = r5(c*(a+b)+d) |
| 73 | + @test res3 === (d, c, a, b) || res3 === (d, c, b, a) |
| 74 | + res4 = r6(c*(a+b)+d) |
| 75 | + @test res4 === (d, c, a, b) || res4 === (d, c, b, a) |
68 | 76 | end
|
69 | 77 |
|
70 | 78 | @testset "Slot matcher with default value" begin
|
|
98 | 106 | @test r_pow2(a+b) === 1
|
99 | 107 |
|
100 | 108 | r_mix = @rule (~x + (~y)*(~!c))^(~!m) => (~m, ~c)
|
101 |
| - @test r_mix((a + b*c)^2) === (2, c) |
102 |
| - @test r_mix((a + b*c)) === (1, c) |
| 109 | + res = r_mix((a + b*c)^2) |
| 110 | + @test res === (2, c) || res === (2, b) |
| 111 | + res = r_mix((a + b*c)) |
| 112 | + @test res === (1, c) || res === (1, b) |
103 | 113 | @test r_mix((a + b)) === (1, 1)
|
104 | 114 |
|
105 | 115 | r_more_than_two_arguments = @rule (~!a)*exp(~x)*sin(~x) => (~a, ~x)
|
|
114 | 124 | # predicate checked in normal matching process
|
115 | 125 | r_predicate1 = @rule x + (~!m::(var->isa(var, Int))) => ~m
|
116 | 126 | @test r_predicate1(x+2) === 2
|
117 |
| - @test r_predicate1(x+2.0) === nothing |
| 127 | + @test r_predicate1(x+2.1) === nothing |
118 | 128 |
|
119 | 129 | # predicate checked in defslot matching process
|
120 | 130 | r_predicate2 = @rule x + ~!m::(var->!(var===0)) => ~m
|
|
135 | 145 | @test r1(1/a) === (a, -1)
|
136 | 146 |
|
137 | 147 | r2 = @rule (~x)^(~y + ~z) => (~x, ~y, ~z) # rule with term as exponent
|
138 |
| - @test r2(1/a^(b+2c)) === (a, -b, -2c) # uses frankestein |
| 148 | + res = r2(1/a^(b+2c)) |
| 149 | + @test res === (a, -b, -2c) || res === (a, -2c, -b) # uses frankestein |
139 | 150 | @test r2(1/a^3) === nothing # should use a term_matcher that flips the sign, but is not implemented
|
140 | 151 |
|
141 | 152 | r1defslot = @rule (~x)^(~!y) => (~x, ~y) # rule with defslot as exponent
|
|
145 | 156 | @test r1defslot(a) === (a, 1)
|
146 | 157 |
|
147 | 158 | r = @rule (~x + ~y)^(~m) => (~x, ~y, ~m) # rule to match (1/...)^(...)
|
148 |
| - @test r((1/(a+b))^3) === (a,b,-3) |
| 159 | + res = r((1/(a+b))^3) |
| 160 | + @test res === (a,b,-3) || res === (b, a, -3) |
149 | 161 | end
|
150 | 162 |
|
151 | 163 | @testset "Return the matches dictionary" begin
|
|
226 | 238 | ex = setmetadata(ex, MetaData, :metadata)
|
227 | 239 | ex1 = ex * b
|
228 | 240 |
|
229 |
| - @test getmetadata(arguments(ex1)[1], MetaData) == :metadata |
| 241 | + @test getmetadata(sorted_arguments(ex1)[1], MetaData) == :metadata |
230 | 242 | end
|
0 commit comments