Sha256: 26f2c7d27fe03e3b308e8bfbcf07063690f69c61a0d400a0c2e985bfcfdfc431

Contents?: true

Size: 1.17 KB

Versions: 17

Compression:

Stored size: 1.17 KB

Contents

require 'test_helper'

require 'rgl/bipartite'
require 'rgl/adjacency'

include RGL

class TestBipartite < Test::Unit::TestCase

  def test_bipartite_sets
    assert_equal([[1, 2, 3], [4, 5, 6]], bipartite_sets(AdjacencyGraph[1,5, 1,6, 2,4, 2,5, 3,4, 3,5, 3,6]))
  end

  def test_bipartite_sets_for_non_bipartite_graph
    assert_equal(nil, bipartite_sets(AdjacencyGraph[1,4, 1,5, 2,3, 2,4, 2,5, 3,5]))
  end

  def test_bipartite_sets_for_directed_graph
    assert_raise(NotUndirectedError, 'bipartite sets can only be found for an undirected graph') do
      DirectedAdjacencyGraph.new.bipartite_sets
    end
  end

  def test_bipartite_sets_for_bipartite_disconnected_graph
    assert_equal([[1, 3], [2, 4]], bipartite_sets(AdjacencyGraph[1,2, 3,4]))
  end

  def test_bipartite_sets_for_non_bipartite_disconnected_graph
    assert_equal(nil, bipartite_sets(AdjacencyGraph[1,2, 3,4, 4,5, 5,3]))
  end

  def test_bipartite
    assert(AdjacencyGraph[1,2, 2,3].bipartite?)
  end

  def test_not_bipartite
    assert(!AdjacencyGraph[1,2, 2,3, 3,1].bipartite?)
  end

  private

  def bipartite_sets(graph)
    sets = graph.bipartite_sets
    sets && sets.map { |set| set.sort }.sort
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rgl-0.6.6 test/bipartite_test.rb
rgl-0.6.5 test/bipartite_test.rb
rgl-0.6.4 test/bipartite_test.rb
rgl-0.6.3 test/bipartite_test.rb
rgl-0.6.2 test/bipartite_test.rb
rgl-0.6.1 test/bipartite_test.rb
rgl-0.6.0 test/bipartite_test.rb
rgl-0.5.10 test/bipartite_test.rb
rgl-0.5.9 test/bipartite_test.rb
rgl-0.5.8 test/bipartite_test.rb
rgl-0.5.7 test/bipartite_test.rb
rgl-0.5.6 test/bipartite_test.rb
rgl-0.5.4 test/bipartite_test.rb
rgl-0.5.3 test/bipartite_test.rb
rgl-0.5.2 test/bipartite_test.rb
rgl-0.5.1 test/bipartite_test.rb
rgl-0.5.0 test/bipartite_test.rb