Skip to content

Commit

Permalink
Merge pull request #362 from oscar-system/enh/graphs_and_multisubobj
Browse files Browse the repository at this point in the history
tests for graphs and multiple subobjects
  • Loading branch information
benlorenz authored Sep 17, 2021
2 parents 51fd248 + ff36f2f commit 60f287e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions test/graphs.jl
Original file line number Diff line number Diff line change
@@ -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

31 changes: 31 additions & 0 deletions test/perlobj.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 60f287e

@benlorenz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/45080

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.8 -m "<description of version>" 60f287ee2119b96b277ba1b72f4560cfa5a6a2be
git push origin v0.5.8

Please sign in to comment.