Sha256: 4b4f9152185f766f1284720f555887596f4d20fccd398eb134753f8013258fb4

Contents?: true

Size: 1.28 KB

Versions: 5

Compression:

Stored size: 1.28 KB

Contents

require 'test/unit'
require 'rgl/implicit'
require 'rgl/adjacency'

include RGL

class TestImplicit < Test::Unit::TestCase
  def setup
    @dg = DirectedAdjacencyGraph.new
    [[1,2],[2,3],[2,4],[4,5],[1,6],[6,4]].each do |(src,target)| 
      @dg.add_edge(src, target)
    end

	@cycle = ImplicitGraph.new { |g|
	  g.vertex_iterator { |b| 0.upto(4,&b) }
	  g.adjacent_iterator { |x, b| b.call((x+1)%5) }
	  g.directed = true
	}
  end

  def test_empty
	empty = ImplicitGraph.new
	assert(empty.empty?)
	assert_equal([],empty.edges)
	assert_equal([],empty.vertices)
  end

  def test_cycle
	assert(!@cycle.empty?)
	assert_equal([0, 1, 2, 3, 4],@cycle.vertices.sort)
	assert_equal("(0-1)(1-2)(2-3)(3-4)(4-0)",@cycle.edges.sort.to_s)
  end
  
  def test_vertex_filtered_graph
	fg = @cycle.vertices_filtered_by {|v| v%2 == 0}
	assert_equal([0, 2, 4],fg.vertices.sort)
	assert_equal("(4-0)",fg.edges.sort.to_s)
	assert(fg.directed?)

	fg = @dg.vertices_filtered_by {|v| v%2 == 0}
	assert_equal([2, 4, 6],fg.vertices.sort)
	assert_equal("(2-4)(6-4)",fg.edges.sort.to_s)
	assert(fg.directed?)
  end

  def test_edge_filtered_graph
	fg = @cycle.edges_filtered_by {|u,v| u+v > 3}
	assert_equal(@cycle.vertices.sort,fg.vertices.sort)
	assert_equal("(2-3)(3-4)(4-0)",fg.edges.sort.to_s)
	assert(fg.directed?)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rgl-0.2.2 tests/TestImplicit.rb
rgl-0.3.0 tests/TestImplicit.rb
rgl-0.3.1 tests/TestImplicit.rb
rgl-0.4.0 tests/TestImplicit.rb
rgl-0.2.3 tests/TestImplicit.rb