require 'test_helper' require 'rgl/adjacency' require 'rgl/traversal' require 'rgl/topsort' require 'rgl/implicit' include RGL class TestTraversal < Test::Unit::TestCase def setup @dg = DirectedAdjacencyGraph.new(Array) edges = [[1, 2], [1, 6], [2, 3], [2, 4], [4, 5], [6, 4]] edges.each do |(src, target)| @dg.add_edge(src, target) end @bfs = @dg.bfs_iterator(1) @dfs = @dg.dfs_iterator(1) @ug = AdjacencyGraph.new(Array) @ug.add_edges(*edges) end def test_bfs_iterator_creation assert(@bfs.at_beginning?) assert(!@bfs.at_end?) assert_equal(1, @bfs.start_vertex) assert_equal(@dg, @bfs.graph) end def test_bfs_visiting expected = [1, 2, 6, 3, 4, 5] assert_equal(expected, @bfs.to_a) assert_equal(expected, @ug.bfs_iterator(1).to_a) assert_equal([2, 1, 3, 4, 6, 5], @ug.bfs_iterator(2).to_a) end def test_bfs_event_handlers expected = <