File: test_search.rb

package info (click to toggle)
ruby-graphviz 1.0.8-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,124 kB
  • ctags: 695
  • sloc: ruby: 7,656; xml: 26; makefile: 17
file content (32 lines) | stat: -rw-r--r-- 813 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'test/unit'
$:.unshift(File.expand_path('../../lib',__FILE__))
require 'graphviz'
require 'graphviz/theory'

class GraphVizSearch < Test::Unit::TestCase
   def setup
      @graph = GraphViz.graph(:G)
      @graph.add_nodes(["A", "B", "C", "D", "E", "F", "G"])
      @graph.add_edges("A", ["B", "C", "E"])
      @graph.add_edges("B", ["D", "F"])
      @graph.add_edges("C", "G")
      @graph.add_edges("F", "E")
      @theory = GraphViz::Theory.new(@graph)
   end

   def test_dfs
      order = []
      @theory.dfs("A") { |node|
         order << node.id
      }
      assert_equal order, ["A", "B", "D", "F", "E", "C", "G"]
   end

   def test_bfs
      order = []
      @theory.bfs("A") { |node|
         order << node.id
      }
      assert_equal order, ["A", "B", "C", "E", "D", "F", "G"]
   end
end