|
| 1 | + |
| 2 | +""" |
| 3 | + Graphs.Test |
| 4 | +
|
| 5 | +A module that provides utilities for testing functions that should work with any `Graphs.AbstractGraph`. |
| 6 | +""" |
| 7 | +module Test |
| 8 | + |
| 9 | +using Graphs |
| 10 | + |
| 11 | +export GenericEdge, GenericGraph, GenericDiGraph |
| 12 | + |
| 13 | +""" |
| 14 | + GenericEdge <: Graphs.AbstractEdge |
| 15 | +
|
| 16 | +An edge type that can be used to tests functions that relay on the Graphs.jl interface. |
| 17 | +
|
| 18 | +""" |
| 19 | +struct GenericEdge{T} <: Graphs.AbstractEdge{T} |
| 20 | + e::Graphs.SimpleEdge{T} |
| 21 | +end |
| 22 | + |
| 23 | +Graphs.src(e::GenericEdge) = Graphs.src(e.e) |
| 24 | + |
| 25 | +Graphs.dst(e::GenericEdge) = Graphs.dst(e.e) |
| 26 | + |
| 27 | +Base.reverse(e::GenericEdge) = GenericEdge(reverse(e.e)) |
| 28 | + |
| 29 | +""" |
| 30 | + GenericGraph{T} <: Graphs.AbstractGraph{T} |
| 31 | +
|
| 32 | +An undirected graph type that can be used to tests functions that relay on the Graphs.jl interface. |
| 33 | +
|
| 34 | +""" |
| 35 | +struct GenericGraph{T} <: Graphs.AbstractGraph{T} |
| 36 | + g::SimpleGraph{T} |
| 37 | +end |
| 38 | + |
| 39 | +""" |
| 40 | + GenericDiGraph{T} <: Graphs.AbstractGraph{T} |
| 41 | +
|
| 42 | +A directed graph type that can be used to tests functions that relay on the Graphs.jl interface. |
| 43 | +
|
| 44 | +""" |
| 45 | +struct GenericDiGraph{T} <: Graphs.AbstractGraph{T} |
| 46 | + g::SimpleDiGraph{T} |
| 47 | +end |
| 48 | + |
| 49 | +Graphs.is_directed(::Type{<:GenericGraph}) = false |
| 50 | +Graphs.is_directed(::Type{<:GenericDiGraph}) = true |
| 51 | + |
| 52 | +Base.eltype(g::GenericGraph) = eltype(g.g) |
| 53 | +Base.eltype(g::GenericDiGraph) = eltype(g.g) |
| 54 | + |
| 55 | +Graphs.edges(g::GenericGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) |
| 56 | +Graphs.edges(g::GenericDiGraph) = (GenericEdge(e) for e in Graphs.edges(g.g)) |
| 57 | + |
| 58 | +Graphs.edgetype(g::GenericGraph) = GenericEdge{eltype(g)} |
| 59 | +Graphs.edgetype(g::GenericDiGraph) = GenericEdge{eltype(g)} |
| 60 | + |
| 61 | +Graphs.has_edge(g::GenericGraph, s, d) = Graphs.has_edge(g.g, s, d) |
| 62 | +Graphs.has_edge(g::GenericDiGraph, s, d) = Graphs.has_edge(g.g, s, d) |
| 63 | + |
| 64 | +Graphs.has_vertex(g::GenericGraph, v) = Graphs.has_vertex(g.g, v) |
| 65 | +Graphs.has_vertex(g::GenericDiGraph, v) = Graphs.has_vertex(g.g, v) |
| 66 | + |
| 67 | +Graphs.inneighbors(g::GenericGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) |
| 68 | +Graphs.inneighbors(g::GenericDiGraph, v) = (u for u in Graphs.inneighbors(g.g, v)) |
| 69 | + |
| 70 | +Graphs.outneighbors(g::GenericGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) |
| 71 | +Graphs.outneighbors(g::GenericDiGraph, v) = (u for u in Graphs.outneighbors(g.g, v)) |
| 72 | + |
| 73 | +Graphs.ne(g::GenericGraph) = Graphs.ne(g.g) |
| 74 | +Graphs.ne(g::GenericDiGraph) = Graphs.ne(g.g) |
| 75 | + |
| 76 | +Graphs.nv(g::GenericGraph) = Graphs.nv(g.g) |
| 77 | +Graphs.nv(g::GenericDiGraph) = Graphs.nv(g.g) |
| 78 | + |
| 79 | +Graphs.vertices(g::GenericGraph) = (v for v in Graphs.vertices(g.g)) |
| 80 | +Graphs.vertices(g::GenericDiGraph) = (v for v in Graphs.vertices(g.g)) |
| 81 | + |
| 82 | +end # module |
0 commit comments