Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ include("vertexcover/random_vertex_cover.jl")
include("Experimental/Experimental.jl")
include("Parallel/Parallel.jl")
include("Test/Test.jl")
include("LEMON/LEMON.jl")

using .LinAlg
using .LEMON
end # module
45 changes: 45 additions & 0 deletions src/LEMON/LEMON.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module LEMON

using Graphs

export LEMONGraph, LEMONDiGraph

abstract type AbstractLEMONGraph <: AbstractGraph{Int} end

struct LEMONGraph <: AbstractLEMONGraph
n::Int
m::Int

function LEMONGraph(n::Integer=0)
n >= 0 || throw(DomainError(n, "Number of vertices must be non-negative"))
return new(n, 0)
end
end

struct LEMONDiGraph <: AbstractLEMONGraph
n::Int
m::Int

function LEMONDiGraph(n::Integer=0)
n >= 0 || throw(DomainError(n, "Number of vertices must be non-negative"))
return new(n, 0)
end
end

Graphs.is_directed(::Type{LEMONGraph}) = false
Graphs.is_directed(::Type{LEMONDiGraph}) = true

Graphs.nv(g::AbstractLEMONGraph) = g.n
Graphs.ne(g::AbstractLEMONGraph) = g.m

Graphs.vertices(g::AbstractLEMONGraph) = 1:nv(g)

function Base.show(io::IO, g::LEMONGraph)
return print(io, "{$(nv(g)), $(ne(g))} undirected LEMON graph")
end

function Base.show(io::IO, g::LEMONDiGraph)
return print(io, "{$(nv(g)), $(ne(g))} directed LEMON graph")
end

end
39 changes: 39 additions & 0 deletions test/LEMON/lemon.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Graphs.LEMON

@testset "LEMON" begin
@testset "Graph Construction" begin
g = LEMONGraph()
@test nv(g) == 0
@test ne(g) == 0
@test !is_directed(g)

g2 = LEMONGraph(5)
@test nv(g2) == 5
@test ne(g2) == 0

@test_throws DomainError LEMONGraph(-1)
end

@testset "DiGraph Construction" begin
g = LEMONDiGraph()
@test nv(g) == 0
@test ne(g) == 0
@test is_directed(g)

g2 = LEMONDiGraph(5)
@test nv(g2) == 5
@test ne(g2) == 0

@test_throws DomainError LEMONDiGraph(-1)
end

@testset "Basic Properties" begin
g = LEMONGraph(10)
@test vertices(g) == 1:10
@test eltype(g) == Int

dg = LEMONDiGraph(10)
@test vertices(dg) == 1:10
@test eltype(dg) == Int
end
end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ tests = [
"vertexcover/random_vertex_cover",
"trees/prufer",
"experimental/experimental",
"LEMON/lemon",
]

@testset verbose = true "Graphs" begin
Expand Down