ruby-graphviz_c 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemrc +0 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/AUTHORS.rdoc +33 -0
- data/CHANGELOG.rdoc +287 -0
- data/COPYING.rdoc +133 -0
- data/Gemfile +4 -0
- data/README.rdoc +206 -0
- data/Rakefile +71 -0
- data/bin/dot2ruby +91 -0
- data/bin/gem2gv +165 -0
- data/bin/git2gv +167 -0
- data/bin/ruby2gv +234 -0
- data/bin/xml2gv +96 -0
- data/examples/dot/JSP.dot +52 -0
- data/examples/dot/balanced.dot +36 -0
- data/examples/dot/cluster.dot +30 -0
- data/examples/dot/dotgraph.dot +28 -0
- data/examples/dot/fsm.dot +20 -0
- data/examples/dot/genetic.dot +118 -0
- data/examples/dot/hello.dot +1 -0
- data/examples/dot/hello_test.rb +33 -0
- data/examples/dot/lion_share.dot +103 -0
- data/examples/dot/prof.dot +150 -0
- data/examples/dot/psg.dot +28 -0
- data/examples/dot/rank.dot +6 -0
- data/examples/dot/sdh.dot +284 -0
- data/examples/dot/siblings.dot +492 -0
- data/examples/dot/so-sample001.gv +30 -0
- data/examples/dot/so-sample002.gv +33 -0
- data/examples/dot/so-sample003.gv +45 -0
- data/examples/dot/test.dot +17 -0
- data/examples/dot/test_parse.rb +13 -0
- data/examples/dot/this_crach_with_dot_2.20.dot +24 -0
- data/examples/dot/unix.dot +104 -0
- data/examples/graphml/attributes.ext.graphml +12 -0
- data/examples/graphml/attributes.graphml +40 -0
- data/examples/graphml/cluster.graphml +75 -0
- data/examples/graphml/failed_graph.graphml +461 -0
- data/examples/graphml/hyper.graphml +29 -0
- data/examples/graphml/nested.graphml +54 -0
- data/examples/graphml/port.graphml +32 -0
- data/examples/graphml/simple.graphml +30 -0
- data/examples/hello.png +0 -0
- data/examples/rgv/rgv.ps +125 -0
- data/examples/rgv/test_rgv.rb +12 -0
- data/examples/sample01.rb +32 -0
- data/examples/sample02.rb +42 -0
- data/examples/sample03.rb +31 -0
- data/examples/sample04.rb +22 -0
- data/examples/sample05.rb +32 -0
- data/examples/sample06.rb +46 -0
- data/examples/sample07.rb +23 -0
- data/examples/sample08.rb +34 -0
- data/examples/sample09.rb +50 -0
- data/examples/sample10.rb +50 -0
- data/examples/sample11.rb +42 -0
- data/examples/sample12.rb +55 -0
- data/examples/sample13.rb +48 -0
- data/examples/sample14.rb +44 -0
- data/examples/sample15.rb +25 -0
- data/examples/sample16.rb +8 -0
- data/examples/sample17.rb +92 -0
- data/examples/sample18.rb +24 -0
- data/examples/sample19.rb +59 -0
- data/examples/sample20.rb +47 -0
- data/examples/sample21.rb +12 -0
- data/examples/sample22.rb +10 -0
- data/examples/sample23.rb +11 -0
- data/examples/sample24.rb +11 -0
- data/examples/sample25.rb +11 -0
- data/examples/sample26.rb +8 -0
- data/examples/sample27.rb +8 -0
- data/examples/sample28.rb +12 -0
- data/examples/sample29.rb +8 -0
- data/examples/sample30.rb +12 -0
- data/examples/sample31.rb +10 -0
- data/examples/sample32.rb +14 -0
- data/examples/sample33.rb +43 -0
- data/examples/sample34.rb +29 -0
- data/examples/sample35.rb +43 -0
- data/examples/sample36.rb +35 -0
- data/examples/sample37.rb +87 -0
- data/examples/sample38.rb +12 -0
- data/examples/sample39.rb +11 -0
- data/examples/sample40.rb +17 -0
- data/examples/sample41.rb +8 -0
- data/examples/sample42.rb +35 -0
- data/examples/sample43.rb +26 -0
- data/examples/sample44.rb +97 -0
- data/examples/sample45.rb +24 -0
- data/examples/sample46.rb +43 -0
- data/examples/sample47.rb +7 -0
- data/examples/sample48.rb +62 -0
- data/examples/sample49.rb +10 -0
- data/examples/sample50.rb +215 -0
- data/examples/sample51.rb +37 -0
- data/examples/sample52.rb +62 -0
- data/examples/sample53.rb +26 -0
- data/examples/sample54.rb +26 -0
- data/examples/sample55.rb +9 -0
- data/examples/sample56.rb +10 -0
- data/examples/sample57.rb +8 -0
- data/examples/sample58.rb +33 -0
- data/examples/sample59.rb +14 -0
- data/examples/sample60.rb +12 -0
- data/examples/sample61.rb +12 -0
- data/examples/sample62.rb +24 -0
- data/examples/sample63.rb +32 -0
- data/examples/sample64.rb +31 -0
- data/examples/sample65.rb +9 -0
- data/examples/sample66.rb +4 -0
- data/examples/sample67.rb +10 -0
- data/examples/sample68.rb +27 -0
- data/examples/sample69.rb +23 -0
- data/examples/sample70.rb +9 -0
- data/examples/sample99.rb +70 -0
- data/examples/sdlshapes/README +2 -0
- data/examples/sdlshapes/sdl.ps +655 -0
- data/examples/sdlshapes/sdlshapes.dot +78 -0
- data/examples/test.xml +26 -0
- data/examples/theory/pert.rb +47 -0
- data/examples/theory/tests.rb +87 -0
- data/lib/ext/gvpr/dot2ruby.g +185 -0
- data/lib/graphviz/attrs.rb +73 -0
- data/lib/graphviz/constants.rb +294 -0
- data/lib/graphviz/core_ext.rb +64 -0
- data/lib/graphviz/dot2ruby.rb +59 -0
- data/lib/graphviz/dot_script.rb +109 -0
- data/lib/graphviz/dsl.rb +67 -0
- data/lib/graphviz/edge.rb +197 -0
- data/lib/graphviz/elements.rb +39 -0
- data/lib/graphviz/ext.rb +17 -0
- data/lib/graphviz/family_tree/couple.rb +63 -0
- data/lib/graphviz/family_tree/generation.rb +39 -0
- data/lib/graphviz/family_tree/person.rb +120 -0
- data/lib/graphviz/family_tree/sibling.rb +13 -0
- data/lib/graphviz/family_tree.rb +118 -0
- data/lib/graphviz/graphml.rb +268 -0
- data/lib/graphviz/math/matrix.rb +221 -0
- data/lib/graphviz/node.rb +160 -0
- data/lib/graphviz/nothugly/nothugly.xsl +321 -0
- data/lib/graphviz/nothugly.rb +63 -0
- data/lib/graphviz/theory.rb +321 -0
- data/lib/graphviz/types/arrow_type.rb +32 -0
- data/lib/graphviz/types/color.rb +58 -0
- data/lib/graphviz/types/color_list.rb +24 -0
- data/lib/graphviz/types/esc_string.rb +20 -0
- data/lib/graphviz/types/gv_bool.rb +49 -0
- data/lib/graphviz/types/gv_double.rb +32 -0
- data/lib/graphviz/types/html_string.rb +18 -0
- data/lib/graphviz/types/lbl_string.rb +22 -0
- data/lib/graphviz/types/rect.rb +35 -0
- data/lib/graphviz/types/spline_type.rb +77 -0
- data/lib/graphviz/types.rb +22 -0
- data/lib/graphviz/utils/colors.rb +1018 -0
- data/lib/graphviz/utils.rb +70 -0
- data/lib/graphviz/xml.rb +119 -0
- data/lib/graphviz.rb +967 -0
- data/lib/ruby-graphviz.rb +1 -0
- data/man/dot2ruby.1 +66 -0
- data/man/dot2ruby.1.ronn +55 -0
- data/man/gem2gv.1 +60 -0
- data/man/gem2gv.1.ronn +47 -0
- data/man/git2gv.1 +48 -0
- data/man/git2gv.1.ronn +40 -0
- data/man/ruby2gv.1 +60 -0
- data/man/ruby2gv.1.ronn +47 -0
- data/man/xml2gv.1 +48 -0
- data/man/xml2gv.1.ronn +39 -0
- data/ruby-graphviz.gemspec +47 -0
- data/setup.rb +1585 -0
- data/test/helper.rb +13 -0
- data/test/support.rb +95 -0
- data/test/test_dot_script.rb +47 -0
- data/test/test_examples.rb +151 -0
- data/test/test_graph.rb +115 -0
- data/test/test_search.rb +29 -0
- data/test/test_subgraph.rb +27 -0
- data/test/test_theory.rb +98 -0
- data/test/test_types.rb +65 -0
- data/test/test_utils_colors.rb +52 -0
- metadata +301 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
cur = Pathname.new(File.expand_path("..", __FILE__))
|
7
|
+
lib = cur.join('..', 'lib')
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(lib.to_s, cur.to_s)
|
10
|
+
require 'graphviz'
|
11
|
+
require 'graphviz/theory'
|
12
|
+
require 'graphviz/math/matrix'
|
13
|
+
require 'graphviz/utils/colors'
|
data/test/support.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
# hack so that the example scripts don't unnecessarily unshift @todo
|
5
|
+
class << $:
|
6
|
+
def unshift path
|
7
|
+
include?(path) ? self : super # super will return self, too
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module TestSupport
|
12
|
+
extend self
|
13
|
+
|
14
|
+
# @todo move to app?
|
15
|
+
def windows?
|
16
|
+
/mswin|mingw/ =~ RUBY_PLATFORM
|
17
|
+
end
|
18
|
+
|
19
|
+
def dev_null
|
20
|
+
windows? ? 'NUL' : '/dev/null'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module IoHack
|
25
|
+
|
26
|
+
#
|
27
|
+
# this is a ridiculous hack to capture what was written to $stdout/$stderr for testing
|
28
|
+
# an alternative is to use Open3.popen3 on external calls which has overhead
|
29
|
+
# and OS dependencies.
|
30
|
+
#
|
31
|
+
# This hack would apparently not be as bad on 1.9, which would allow you to simply
|
32
|
+
# set $stdout and $stderr to instances of StringIO
|
33
|
+
#
|
34
|
+
# I don't know what is the 'right way' to test this kind of thing
|
35
|
+
#
|
36
|
+
|
37
|
+
class IoHackStream < File
|
38
|
+
#
|
39
|
+
# pre 1.9 you can't assign $stdout and $stderr to anything other than
|
40
|
+
# an IO::File instance. what we *want* is to have them be StringIOs that
|
41
|
+
# we can read from like strings for testing. So this is a crazy proxy
|
42
|
+
# around StringIO. Note it makes *all* methods except a few protected,
|
43
|
+
# which for me was failing silently when i forgot to make the appropriate
|
44
|
+
# ones public. hack!
|
45
|
+
#
|
46
|
+
|
47
|
+
except = %w(inspect kind_of?)
|
48
|
+
except += except.map{|x| x.to_sym } # for Ruby 1.9
|
49
|
+
these = ancestors[0].instance_methods
|
50
|
+
# these = [1,2,3].map{|x| ancestors[x].instance_methods(false)}.flatten
|
51
|
+
eraseme = (these - except)
|
52
|
+
eraseme.each{ |name| protected name }
|
53
|
+
attr_reader :io
|
54
|
+
def initialize()
|
55
|
+
@io = StringIO.new
|
56
|
+
super(TestSupport.dev_null, 'r+') # probably doesn't matter the mode
|
57
|
+
end
|
58
|
+
these = %w(write << puts)
|
59
|
+
these.each do |name|
|
60
|
+
define_method(name) do |*a|
|
61
|
+
@io.send(name, *a)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def fake_popen2 path
|
67
|
+
push_io
|
68
|
+
require path # caller assumes responsibility for exceptions vis-a-vis stack
|
69
|
+
pop_io
|
70
|
+
end
|
71
|
+
|
72
|
+
def io_stack
|
73
|
+
@io_stack ||= []
|
74
|
+
end
|
75
|
+
|
76
|
+
def push_io
|
77
|
+
io_stack.push [$stdout, $stderr]
|
78
|
+
$stdout = IoHackStream.new
|
79
|
+
$stderr = IoHackStream.new
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def pop_io
|
84
|
+
fail('stack empty') unless io_stack.any?
|
85
|
+
result = [$stdout, $stderr]
|
86
|
+
$stdout, $stderr = io_stack.pop
|
87
|
+
result.each_with_index do |io,idx|
|
88
|
+
if io.kind_of? IoHackStream
|
89
|
+
io.io.seek(0)
|
90
|
+
result[idx] = io.io.read
|
91
|
+
end
|
92
|
+
end
|
93
|
+
result
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class GraphVizDOTScriptTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@script = GraphViz::DOTScript.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_appends_a_newline_character_if_it_is_missing
|
9
|
+
str = "Test without newline"
|
10
|
+
@script.append(str)
|
11
|
+
assert_equal @script.to_s, str + "\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_does_not_append_a_newline_if_already_present
|
15
|
+
str = "Linebreak follows at my tail:\n"
|
16
|
+
@script.append(str)
|
17
|
+
assert_equal @script.to_s, str
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_can_prepend_lines_to_its_content
|
21
|
+
start_content = "I want to be at the top!\n"
|
22
|
+
additional_content = "No way!\n"
|
23
|
+
|
24
|
+
@script.append(start_content)
|
25
|
+
@script.prepend(additional_content)
|
26
|
+
|
27
|
+
assert_equal @script.to_s, additional_content + start_content
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_can_add_types_with_data
|
31
|
+
data = "some random data"
|
32
|
+
@script.add_type("node_attr", data)
|
33
|
+
assert_match(/\s*node\s*\[\s*#{data}\s*\]\s*/, @script.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_does_nothing_if_data_is_empty
|
37
|
+
@script.add_type("anything", "")
|
38
|
+
assert_equal true, @script.to_s.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_raises_an_argument_error_on_unknown_types
|
42
|
+
assert_raise ArgumentError do
|
43
|
+
@script.add_type("invalid", "some data")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,151 @@
|
|
1
|
+
#require File.expand_path('support.rb', File.dirname(__FILE__))
|
2
|
+
require 'support'
|
3
|
+
|
4
|
+
class GraphVizTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
#
|
7
|
+
# you can run a subset of all the samples like this:
|
8
|
+
# ruby test/test_examples.rb --name='/sample3[6-9]/'
|
9
|
+
#
|
10
|
+
# The above will run samples 36, 37, 38, and 39
|
11
|
+
#
|
12
|
+
|
13
|
+
|
14
|
+
include IoHack
|
15
|
+
|
16
|
+
RootDir = File.expand_path('../..', __FILE__)
|
17
|
+
ExampleDir = File.join(RootDir,'examples')
|
18
|
+
OutputDir = File.join(File.dirname(__FILE__),'output')
|
19
|
+
# OutputDir = File.join(RootDir,'test','output')
|
20
|
+
|
21
|
+
|
22
|
+
# the below tests write to stdout. the other tests write to filesystem
|
23
|
+
|
24
|
+
Skips = {
|
25
|
+
#'35' => 'hanging for me',
|
26
|
+
'33' => 'FamilyTree is broken',
|
27
|
+
'36' => 'hangs for me',
|
28
|
+
'53' => 'FamilyTree is broken',
|
29
|
+
'57' => 'will not be able to find the graphml script',
|
30
|
+
'98' => 'This test is just for debug',
|
31
|
+
'99' => 'FamilyTree is broken'
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
def test_sample07
|
36
|
+
assert_output_pattern(/\Adigraph structs \{.+\}\n\Z/m, '07')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_sample22
|
40
|
+
assert_output_pattern(/\Adigraph mainmap \{.+\}\n\Z/m, '22')
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_sample23
|
44
|
+
assert_output_pattern(%r{\A<map.+</map>\n\Z}m, '23')
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_sample27
|
48
|
+
assert_output_pattern(/\Adigraph G \{.*\}\n\Z/m, '27')
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_sample38
|
52
|
+
assert_output_pattern(/\Adigraph G \{.*\}\n\Z/m, '38')
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_sample40
|
56
|
+
assert_output_pattern(/\Adigraph G \{.*\}\n\Z/m, '40')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_sample41
|
60
|
+
assert_output_pattern(/\A.*\Z/m, '40')
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_sample55
|
64
|
+
assert_output_pattern(/\Agraph G \{.*\}\n\Z/m, '55')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_sample62
|
68
|
+
assert_output_pattern(/\ANode.*\n\Z/m, '62')
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_sample70
|
72
|
+
assert_output_pattern(/\Agraph G \{.*\}\n\Z/m, '70')
|
73
|
+
end
|
74
|
+
|
75
|
+
#
|
76
|
+
# for every sample file in the examples directory that matches the
|
77
|
+
# pattern ("sample01.rb, sample02.rb, etc) make a corresponding
|
78
|
+
# test method: test_sample01(), test_sample02(), etc. To actually define
|
79
|
+
# this methods in this way instead of just iterating over the list of files
|
80
|
+
# will make it easier to use command-line options to isolate certain
|
81
|
+
# tests,
|
82
|
+
# (for example: ruby test/test_examples.rb --name '/sample0[1-5]/' )
|
83
|
+
# and to integrate better with certain kinds of test output and
|
84
|
+
# reporting tools.
|
85
|
+
#
|
86
|
+
# we will skip over any methods already defined
|
87
|
+
#
|
88
|
+
|
89
|
+
@last_image_path = nil
|
90
|
+
@number_to_path = {}
|
91
|
+
class << self
|
92
|
+
def make_sample_test_method path
|
93
|
+
fail("failed match: #{path}") unless
|
94
|
+
matches = %r{/(sample(\d\d))\.rb\Z}.match(path)
|
95
|
+
basename, number = matches.captures
|
96
|
+
number_to_path[number] = path
|
97
|
+
meth = "test_#{basename}"
|
98
|
+
return if method_defined?(meth) # if we hand-write one
|
99
|
+
if Skips[number]
|
100
|
+
puts "skipping #{basename} - #{Skips[number]}"
|
101
|
+
return
|
102
|
+
end
|
103
|
+
define_method(meth){ assert_sample_file_has_no_output(path) }
|
104
|
+
end
|
105
|
+
attr_accessor :last_image_path, :number_to_path
|
106
|
+
end
|
107
|
+
|
108
|
+
samples = Dir[File.join(ExampleDir,'sample*.rb')].sort
|
109
|
+
samples.each {|path| make_sample_test_method(path) }
|
110
|
+
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def assert_output_pattern tgt_regexp, number
|
115
|
+
path = self.class.number_to_path[number]
|
116
|
+
setup_sample path
|
117
|
+
out, err = fake_popen2(path)
|
118
|
+
assert_equal "", err, "no errors"
|
119
|
+
assert_match tgt_regexp, out.gsub(/\r\n/, "\n"), "output for sample#{number} should match regexp"
|
120
|
+
end
|
121
|
+
|
122
|
+
def assert_sample_file_has_no_output path
|
123
|
+
setup_sample(path)
|
124
|
+
begin
|
125
|
+
out, err = fake_popen2(path)
|
126
|
+
assert_equal(0, out.length, "expecting empty output")
|
127
|
+
assert_equal(0, err.length, "expecting empty errorput")
|
128
|
+
msg = "maybe generated #{self.class.last_image_path}"
|
129
|
+
print "\n", msg
|
130
|
+
rescue Exception => e
|
131
|
+
assert(false, "got exception on #{File.basename(path)}: #{e.message}")
|
132
|
+
puts "out: ", out.inspect, "err:", err.inspect
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def setup_sample path
|
137
|
+
unless File.directory? OutputDir
|
138
|
+
FileUtils.mkdir_p(OutputDir, :verbose => true)
|
139
|
+
end
|
140
|
+
ARGV[0] = nil if ARGV.any? # hack trigger searching for 'dot' executable
|
141
|
+
hack_output_path path
|
142
|
+
end
|
143
|
+
|
144
|
+
def hack_output_path path
|
145
|
+
# hack $0 to change where the output image is written to
|
146
|
+
fake_example_path = File.join(OutputDir, File.basename(path))
|
147
|
+
$program_name = fake_example_path.dup
|
148
|
+
alias $0 $program_name
|
149
|
+
self.class.last_image_path = "#{$0}.png"
|
150
|
+
end
|
151
|
+
end
|
data/test/test_graph.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class GraphVizTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@graph = GraphViz::new( :G )
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_graph
|
9
|
+
assert(@graph, 'Create graph faild.')
|
10
|
+
|
11
|
+
assert_block 'Set attribut for graph faild.' do
|
12
|
+
@graph['size'] = "10,10"
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_equal( "\"10,10\"", @graph['size'].to_s, 'Get attribut for graph faild.' )
|
16
|
+
|
17
|
+
assert_equal( "G", @graph.name, "Wrong graph name." )
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_node
|
21
|
+
n, m = nil, nil
|
22
|
+
|
23
|
+
assert_block 'Create node failed.' do
|
24
|
+
n = @graph.add_nodes( "n1" )
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_block 'Get node failed.' do
|
28
|
+
m = @graph.get_node( "n1" )
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_equal( m, n, "Node corrupted when get." )
|
32
|
+
|
33
|
+
assert_equal( @graph.node_count, 1, "Wrong number of nodes" )
|
34
|
+
|
35
|
+
assert_block 'Set attribut for node faild.' do
|
36
|
+
n['label'] = "Hello\n\"world\"\\l"
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal( "\"Hello\\n\\\"world\\\"\\l\"", n['label'].to_s, 'Get attribut for node faild.' )
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_search
|
43
|
+
g = GraphViz::new( "G" )
|
44
|
+
g.node["shape"] = "ellipse"
|
45
|
+
g.node["color"] = "black"
|
46
|
+
|
47
|
+
g["color"] = "black"
|
48
|
+
|
49
|
+
c0 = g.add_graph( "cluster0" )
|
50
|
+
c0["label"] = "process #1"
|
51
|
+
c0["style"] = "filled"
|
52
|
+
c0["color"] = "lightgrey"
|
53
|
+
a0 = c0.add_nodes( "a0", "style" => "filled", "color" => "white" )
|
54
|
+
a1 = c0.add_nodes( "a1", "style" => "filled", "color" => "white" )
|
55
|
+
a2 = c0.add_nodes( "a2", "style" => "filled", "color" => "white" )
|
56
|
+
a3 = c0.add_nodes( "a3", "style" => "filled", "color" => "white" )
|
57
|
+
c0.add_edges( a0, a1 )
|
58
|
+
c0.add_edges( a1, a2 )
|
59
|
+
c0.add_edges( a2, a3 )
|
60
|
+
|
61
|
+
c1 = g.add_graph( "cluster1", "label" => "process #2" )
|
62
|
+
b0 = c1.add_nodes( "b0", "style" => "filled", "color" => "blue" )
|
63
|
+
b1 = c1.add_nodes( "b1", "style" => "filled", "color" => "blue" )
|
64
|
+
b2 = c1.add_nodes( "b2", "style" => "filled", "color" => "blue" )
|
65
|
+
b3 = c1.add_nodes( "b3", "style" => "filled", "color" => "blue" )
|
66
|
+
c1.add_edges( b0, b1 )
|
67
|
+
c1.add_edges( b1, b2 )
|
68
|
+
c1.add_edges( b2, b3 )
|
69
|
+
|
70
|
+
start = g.add_nodes( "start", "shape" => "Mdiamond" )
|
71
|
+
endn = g.add_nodes( "end", "shape" => "Msquare" )
|
72
|
+
|
73
|
+
g.add_edges( start, a0 )
|
74
|
+
g.add_edges( start, b0 )
|
75
|
+
g.add_edges( a1, b3 )
|
76
|
+
g.add_edges( b2, a3 )
|
77
|
+
g.add_edges( a3, a0 )
|
78
|
+
g.add_edges( a3, endn )
|
79
|
+
|
80
|
+
assert g
|
81
|
+
|
82
|
+
assert_equal g.get_node("start"), start
|
83
|
+
assert_equal g.find_node("start"), start
|
84
|
+
assert_equal g.search_node("start"), start
|
85
|
+
|
86
|
+
assert_nil g.get_node("a0")
|
87
|
+
assert_equal g.find_node("a0"), a0
|
88
|
+
assert_equal g.search_node("a0"), a0
|
89
|
+
|
90
|
+
assert_nil c0.get_node("start")
|
91
|
+
assert_equal c0.find_node("start"), start
|
92
|
+
assert_nil c0.search_node("start")
|
93
|
+
|
94
|
+
assert_equal c0.get_node("a0"), a0
|
95
|
+
assert_equal c0.find_node("a0"), a0
|
96
|
+
assert_equal c0.search_node("a0"), a0
|
97
|
+
|
98
|
+
assert_nil c1.get_node("start")
|
99
|
+
assert_equal c1.find_node("start"), start
|
100
|
+
assert_nil c1.search_node("start")
|
101
|
+
|
102
|
+
assert_nil c1.get_node("a0")
|
103
|
+
assert_equal c1.find_node("a0"), a0
|
104
|
+
assert_nil c1.search_node("a0")
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_to_s
|
108
|
+
assert_nothing_raised 'to_s with edge with numeric label failed.' do
|
109
|
+
a = @graph.add_nodes('a')
|
110
|
+
b = @graph.add_nodes('b')
|
111
|
+
@graph.add_edges(a, b, :label => 5)
|
112
|
+
@graph.to_s
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
data/test/test_search.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class GraphVizSearch < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@graph = GraphViz.graph(:G)
|
6
|
+
@graph.add_nodes(["A", "B", "C", "D", "E", "F", "G"])
|
7
|
+
@graph.add_edges("A", ["B", "C", "E"])
|
8
|
+
@graph.add_edges("B", ["D", "F"])
|
9
|
+
@graph.add_edges("C", "G")
|
10
|
+
@graph.add_edges("F", "E")
|
11
|
+
@theory = GraphViz::Theory.new(@graph)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_dfs
|
15
|
+
order = []
|
16
|
+
@theory.dfs("A") { |node|
|
17
|
+
order << node.id
|
18
|
+
}
|
19
|
+
assert_equal order, ["A", "B", "D", "F", "E", "C", "G"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_bfs
|
23
|
+
order = []
|
24
|
+
@theory.bfs("A") { |node|
|
25
|
+
order << node.id
|
26
|
+
}
|
27
|
+
assert_equal order, ["A", "B", "C", "E", "D", "F", "G"]
|
28
|
+
end
|
29
|
+
end
|