diff --git a/src/convert.jl b/src/convert.jl index 1111452c..d80288f2 100644 --- a/src/convert.jl +++ b/src/convert.jl @@ -79,6 +79,7 @@ convert_to_pm_type(::Type{<:AbstractSparseMatrix{<:Union{Bool, CxxWrap.CxxBool}} convert_to_pm_type(::Type{<:Union{AbstractSparseVector, SparseVector}}) = SparseVector convert_to_pm_type(::Type{<:Array}) = Array convert_to_pm_type(::Type{<:Union{Pair, <:StdPair}}) = StdPair +convert_to_pm_type(::Type{<:Graph{T}}) where T<:Union{Directed,Undirected} = Graph{T} # convert_to_pm_type(::Type{<:Union{AbstractSet, Set}}) = Set # specific converts for container types we wrap: diff --git a/test/graphs.jl b/test/graphs.jl new file mode 100644 index 00000000..d181635a --- /dev/null +++ b/test/graphs.jl @@ -0,0 +1,30 @@ +@testset "Polymake.Graph" begin + IntTypes = [Int64] + + @testset "constructors" begin + c = Polymake.polytope.cube(3) + eg = c.GRAPH.ADJACENCY + @test Polymake.nv(eg) == 8 + @test Polymake.ne(eg) == 12 + g = Polymake.Graph{Polymake.Directed}(5) + @test Polymake.nv(g) == 5 + @test Polymake.ne(g) == 0 + end + + @testset "manipulating edges and vertices" begin + g = Polymake.Graph{Polymake.Directed}(5) + Polymake._add_edge(g, 0, 1) + @test Polymake.ne(g) == 1 + @test Polymake._has_edge(g, 0, 1) + @test !Polymake._has_edge(g, 1, 0) + @test !Polymake._has_vertex(g, 5) + Polymake._add_vertex(g) + @test Polymake._has_vertex(g, 5) + Polymake._rem_vertex(g, 5) + @test !Polymake._has_vertex(g, 5) + Polymake._rem_edge(g, 0, 1) + @test !Polymake._has_edge(g, 0, 1) + end + +end + diff --git a/test/perlobj.jl b/test/perlobj.jl index 6b1001f8..784bc334 100644 --- a/test/perlobj.jl +++ b/test/perlobj.jl @@ -241,6 +241,37 @@ @test p.LP.LINEAR_OBJECTIVE == x.LP.LINEAR_OBJECTIVE end + @testset "multiple subobjects" begin + p = polytope.Polytope( INEQUALITIES=[1 1 -1; -1 0 1; 7 -1 -1] ) + lp1 = polytope.LinearProgram(LINEAR_OBJECTIVE=[0,1,0]) + lp2 = polytope.LinearProgram(LINEAR_OBJECTIVE=[0,0,1]) + lp3 = polytope.LinearProgram(LINEAR_OBJECTIVE=[0,2,1]) + p.LP = lp1 + Polymake.add(p,"LP",lp2) + Polymake.add(p,"LP","third",lp3) + @test Polymake._lookup_multi(p,"LP") isa Polymake.Array{Polymake.BigObject} + @test length(Polymake._lookup_multi(p,"LP")) == 3 + @test Polymake._lookup_multi(p,"LP","third").LINEAR_OBJECTIVE == lp3.LINEAR_OBJECTIVE + @test Polymake._lookup_multi(p,"LP",1).LINEAR_OBJECTIVE == lp2.LINEAR_OBJECTIVE + @test p.LP.LINEAR_OBJECTIVE == lp1.LINEAR_OBJECTIVE + @test_throws ErrorException Polymake._lookup_multi(p,"LP",3) + @test_throws ErrorException Polymake._lookup_multi(p,"LP","nonexisting") + end + + @testset "bigobject array" begin + c = polytope.cube(3) + c_type = Polymake.bigobject_type(c) + @test Polymake.Array{Polymake.BigObject}(c_type,2) isa Polymake.Array{Polymake.BigObject} + arr = Polymake.Array{Polymake.BigObject}(c_type,2) + @test length(arr) == 2 + arr[1] = c + arr[2] = polytope.simplex(2) + @test arr[1] isa Polymake.BigObject + @test arr[2] isa Polymake.BigObject + @test arr[1].N_VERTICES == 8 + end + + @testset "toplevel visual" begin @test visual(polytope.cube(3)) isa Polymake.Visual end diff --git a/test/runtests.jl b/test/runtests.jl index 1c9373df..2df3c769 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -28,6 +28,7 @@ struct MyInt x::Int end # needed in test/convert.jl include("pairs.jl") include("lists.jl") include("map.jl") + include("graphs.jl") if get(ENV, "POLYDB_TEST_URI", "") != "" include("polydb.jl") end