class TestImplicit

Public Instance Methods

setup() click to toggle source
# File test/implicit_test.rb, line 9
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
test_cycle() click to toggle source
# File test/implicit_test.rb, line 29
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.join)
end
test_edge_filtered_graph() click to toggle source
# File test/implicit_test.rb, line 47
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.join)
  assert(fg.directed?)
end
test_empty() click to toggle source
# File test/implicit_test.rb, line 22
def test_empty
  empty = ImplicitGraph.new
  assert(empty.empty?)
  assert_equal([], empty.edges)
  assert_equal([], empty.vertices)
end
test_vertex_filtered_graph() click to toggle source
# File test/implicit_test.rb, line 35
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.join)
  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.join)
  assert(fg.directed?)
end