diff --git a/src/library/function/term.jl b/src/library/function/term.jl index c12755c..5230a29 100644 --- a/src/library/function/term.jl +++ b/src/library/function/term.jl @@ -59,15 +59,15 @@ function varlt(u::Term{V}, v::Term{V}) where {V} end function varmul(u::Term{V}, v::Term{V}) where {V} - return Term{V}(sortedmergewith(u.ω, v.ω)) + return Term{V}(sortedmergewith(u.ω, v.ω; lt = varlt)) end function varmul(u::Term{V}, v::V) where {V} - return Term{V}(sortedmergewith(u.ω, V[v])) + return Term{V}(sortedmergewith(u.ω, V[v]; lt = varlt)) end function varmul(u::V, v::Term{V}) where {V} - return Term{V}(sortedmergewith(V[u], v.ω)) + return Term{V}(sortedmergewith(V[u], v.ω; lt = varlt)) end function varmul(u::V, v::V) where {V} diff --git a/test/assets/assets.jl b/test/assets/assets.jl index a8adcb0..522c491 100644 --- a/test/assets/assets.jl +++ b/test/assets/assets.jl @@ -53,10 +53,14 @@ end const VI = VariableIndex -function PBO.varlt(u::VariableIndex, v::VariableIndex)::Bool +function PBO.varlt(u::VariableIndex, v::VariableIndex) return PBO.varlt(u.index, v.index) end +function PBO.varshow(v::VariableIndex) + return PBO.varshow(v.index) +end + # Test foreign packages function run_foreign_pkg_tests(pkg_name::AbstractString, dep_path::AbstractString = PBO.__PROJECT__; kws...) @info "Running Tests for '$pkg_name'" diff --git a/test/integration/interface.jl b/test/integration/interface.jl index a5f4090..97923d3 100644 --- a/test/integration/interface.jl +++ b/test/integration/interface.jl @@ -15,6 +15,40 @@ function test_variable_interface() @test PBO.varlt(VI(1), VI(-1)) === true @test PBO.varlt(VI(-1), VI(1)) === false @test PBO.varlt(VI(-1), VI(-1)) === false + + @test PBO.Term([VI(4), VI(2), VI(1), VI(2), VI(4)]) == PBO.Term{VI}([VI(1), VI(2), VI(4)]) + end + + @testset "varshow" begin + @test PBO.varshow(VI(101)) == "x₁₀₁" + @test PBO.varshow(VI(-12)) == "x₋₁₂" + + @test PBO.varshow(PBO.Term([VI(1), VI(2), VI(4)])) == "x₁ x₂ x₄" + end + + @testset "varmul" begin + let x = VI(1) + y = VI(2) + z = VI(3) + + let xy = PBO.Term([x, y]) + xz = PBO.Term([x, z]) + yz = PBO.Term([y, z]) + + @test PBO.varmul(x, y) == xy + @test PBO.varmul(y, x) == xy + + @test PBO.varmul(x, z) == xz + @test PBO.varmul(z, x) == xz + + @test PBO.varmul(y, z) == yz + @test PBO.varmul(z, y) == yz + + @test PBO.varmul(xy, z) == PBO.Term([x, y, z]) + @test PBO.varmul(xz, y) == PBO.Term([x, y, z]) + @test PBO.varmul(x, yz) == PBO.Term([x, y, z]) + end + end end end