diff --git a/src/traversals/bipartition.jl b/src/traversals/bipartition.jl index 1d1310c18..955b8c21c 100644 --- a/src/traversals/bipartition.jl +++ b/src/traversals/bipartition.jl @@ -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) diff --git a/test/traversals/bipartition.jl b/test/traversals/bipartition.jl index 31736078a..c8d390fa7 100644 --- a/test/traversals/bipartition.jl +++ b/test/traversals/bipartition.jl @@ -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