Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Bug of bipartite_map on Graphs of order 2 #836

Merged
merged 1 commit into from
Feb 9, 2018
Merged
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
4 changes: 2 additions & 2 deletions src/traversals/bipartition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ An empty graph will return an empty vector but is bipartite.
function bipartite_map(g::AbstractGraph{T}) where T
nvg = nv(g)
if !is_directed(g)
ccs = filter(x -> length(x) > 2, connected_components(g))
ccs = filter(x -> length(x) >= 2, connected_components(g))
else
ccs = filter(x -> length(x) > 2, weakly_connected_components(g))
ccs = filter(x -> length(x) >= 2, weakly_connected_components(g))
end
seen = zeros(Bool, nvg)
colors = zeros(Bool, nvg)
Expand Down
22 changes: 21 additions & 1 deletion test/traversals/bipartition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,29 @@
g10 = CompleteBipartiteGraph(10, 10)
for g in testgraphs(g10)
T = eltype(g)
@test @inferred(bipartite_map(g10)) == Vector{T}([ones(T, 10); 2 * ones(T, 10)])
@test @inferred(bipartite_map(g)) == Vector{T}([ones(T, 10); 2 * ones(T, 10)])

h = blkdiag(g, g)
@test @inferred(bipartite_map(h)) == Vector{T}([ones(T, 10); 2 * ones(T, 10); ones(T, 10); 2 * ones(T, 10)])
end

g2 = CompleteGraph(2)
for g in testgraphs(g2)
@test @inferred(bipartite_map(g)) == Vector{eltype(g)}([1, 2])
end

g2 = Graph(2)
for g in testgraphs(g2)
@test @inferred(bipartite_map(g)) == Vector{eltype(g)}([1, 1])
end

g2 = DiGraph(2)
for g in testdigraphs(g2)
@test @inferred(bipartite_map(g)) == Vector{eltype(g)}([1, 1])
end

g2 = PathDiGraph(2)
for g in testdigraphs(g2)
@test @inferred(bipartite_map(g)) == Vector{eltype(g)}([1, 2])
end
end