|
1 | 1 | using SymbolicUtils, Test |
2 | | -using SymbolicUtils: Term, Add, Mul, Div, Pow, hash2, metadata |
| 2 | +using SymbolicUtils: Term, Add, Mul, Div, Pow, hash2, metadata, BasicSymbolic, Symbolic, |
| 3 | + isequal_with_metadata |
| 4 | +import TermInterface |
3 | 5 |
|
4 | 6 | struct Ctx1 end |
5 | 7 | struct Ctx2 end |
|
147 | 149 | @test ex2.hash2[] != h |
148 | 150 | end |
149 | 151 | end |
| 152 | + |
| 153 | +struct MySymbolic <: Symbolic{Real} |
| 154 | + sym::BasicSymbolic{Real} |
| 155 | +end |
| 156 | + |
| 157 | +TermInterface.iscall(x::MySymbolic) = iscall(x.sym) |
| 158 | +TermInterface.operation(x::MySymbolic) = operation(x.sym) |
| 159 | +TermInterface.arguments(x::MySymbolic) = arguments(x.sym) |
| 160 | +SymbolicUtils.metadata(x::MySymbolic) = metadata(x.sym) |
| 161 | +Base.isequal(a::MySymbolic, b::MySymbolic) = isequal(a.sym, b.sym) |
| 162 | + |
| 163 | +@testset "`isequal_with_metadata` on custom symbolics" begin |
| 164 | + @syms x::Real |
| 165 | + xx = setmetadata(x, Int, 3) |
| 166 | + @test isequal(x, xx) |
| 167 | + @test !isequal_with_metadata(x, xx) |
| 168 | + myx = MySymbolic(x) |
| 169 | + myxx = MySymbolic(xx) |
| 170 | + @test isequal(myx, myxx) |
| 171 | + @test !isequal_with_metadata(myx, myxx) |
| 172 | + |
| 173 | + ex = 2x |
| 174 | + exx = 2xx |
| 175 | + myex = MySymbolic(ex) |
| 176 | + myexx = MySymbolic(exx) |
| 177 | + @test isequal(ex, exx) |
| 178 | + @test !isequal_with_metadata(ex, exx) |
| 179 | + @test isequal(myex, myexx) |
| 180 | + @test !isequal_with_metadata(myex, myexx) |
| 181 | + |
| 182 | + t = Term{Real}(max, Any[x, myex]) |
| 183 | + tt = Term{Real}(max, Any[xx, myexx]) |
| 184 | + @test isequal(t, tt) |
| 185 | + @test !isequal_with_metadata(t, tt) |
| 186 | + myt = MySymbolic(t) |
| 187 | + mytt = MySymbolic(tt) |
| 188 | + @test isequal(myt, mytt) |
| 189 | + @test !isequal_with_metadata(myt, mytt) |
| 190 | +end |
0 commit comments