yargi 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +54 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +15 -0
- data/README.md +128 -0
- data/Rakefile +23 -0
- data/examples/fs2dot.rb +1 -1
- data/examples/random.rb +20 -0
- data/lib/yargi.rb +8 -10
- data/lib/yargi/decorate.rb +55 -0
- data/lib/yargi/digraph.rb +71 -46
- data/lib/yargi/digraph_edge.rb +23 -23
- data/lib/yargi/digraph_vertex.rb +27 -27
- data/lib/yargi/edge_set.rb +12 -12
- data/lib/yargi/element_set.rb +54 -54
- data/lib/yargi/loader.rb +1 -0
- data/lib/yargi/markable.rb +12 -12
- data/lib/yargi/predicate.rb +62 -43
- data/lib/yargi/random.rb +98 -0
- data/lib/yargi/version.rb +14 -0
- data/lib/yargi/vertex_set.rb +12 -12
- data/spec/spec_helper.rb +2 -0
- data/spec/test_decorate.rb +28 -0
- data/spec/test_digraph.rb +42 -0
- data/spec/test_random.rb +45 -0
- data/spec/test_yargi.rb +8 -0
- data/tasks/debug_mail.rake +75 -0
- data/tasks/debug_mail.txt +13 -0
- data/tasks/gem.rake +68 -0
- data/tasks/spec_test.rake +71 -0
- data/tasks/unit_test.rake +76 -0
- data/tasks/yard.rake +51 -0
- data/test/test_all.rb +1 -1
- data/test/yargi/README-example.gif +0 -0
- data/test/yargi/digraph_set_features_test.rb +14 -16
- data/test/yargi/digraph_test.rb +33 -33
- data/test/yargi/digraph_vertex_test.rb +9 -9
- data/test/yargi/documentation_test.rb +7 -7
- data/test/yargi/edge_set_test.rb +3 -3
- data/test/yargi/element_set_test.rb +2 -2
- data/test/yargi/hypotheses_test.rb +4 -4
- data/test/yargi/markable_test.rb +11 -11
- data/test/yargi/predicate_test.rb +14 -14
- data/test/yargi/source-sink.gif +0 -0
- data/test/yargi/vertex_set_test.rb +7 -7
- data/yargi.gemspec +187 -0
- data/yargi.noespec +23 -0
- metadata +110 -38
- data/CONTRIBUTE +0 -11
- data/LICENCE +0 -25
- data/README +0 -79
- data/examples/fs2dot.dot +0 -78
- data/examples/fs2dot.gif +0 -0
data/test/test_all.rb
CHANGED
Binary file
|
@@ -2,14 +2,14 @@ require 'test/unit'
|
|
2
2
|
require 'yargi'
|
3
3
|
|
4
4
|
module Yargi
|
5
|
-
|
5
|
+
|
6
6
|
# Tests all set-based features on graphs
|
7
7
|
class DigraphSetFeaturesTest < Test::Unit::TestCase
|
8
|
-
|
8
|
+
|
9
9
|
module Source; end
|
10
10
|
module Sink; end
|
11
11
|
module Additional; end
|
12
|
-
|
12
|
+
|
13
13
|
# Installs the souce-sink graph example under @graph
|
14
14
|
def setup
|
15
15
|
@graph = Yargi::Digraph.new
|
@@ -17,14 +17,14 @@ module Yargi
|
|
17
17
|
sinks = @graph.add_n_vertices(5, Sink)
|
18
18
|
@graph.connect(sources, sinks)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def test_tag
|
22
22
|
@graph.vertices{|v| Source===v}.tag(Additional)
|
23
23
|
@graph.vertices.each {|v| assert_equal((Source===v), (Additional===v))}
|
24
24
|
assert @graph.vertices{|v| Source===v}.all?{|v|Additional===v}
|
25
25
|
assert @graph.vertices{|v| Sink===v}.all?{|v|not(Additional===v)}
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def test_set_and_get_mark
|
29
29
|
@graph.vertices{|v| Source===v}.set_mark(:kind, :source)
|
30
30
|
@graph.vertices{|v| Sink===v}.set_mark(:kind, :sink)
|
@@ -36,29 +36,29 @@ module Yargi
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_add_marks
|
41
41
|
@graph.vertices{|v| Source===v}.add_marks(:kind => :source, :priority => 1.0)
|
42
42
|
@graph.vertices.each do |v|
|
43
43
|
if Source===v
|
44
44
|
assert_equal :source, v.kind
|
45
45
|
assert_equal 1.0, v.priority
|
46
|
-
end
|
46
|
+
end
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_add_marks_with_block
|
51
51
|
@graph.vertices{|v| Source===v}.add_marks do |v|
|
52
52
|
v.set_mark(:test, true)
|
53
53
|
{:kind => :source, :priority => 1.0}
|
54
54
|
end
|
55
55
|
@graph.vertices{|v| Source===v}.all? do |v|
|
56
|
-
assert v.test==true
|
56
|
+
assert v.test==true
|
57
57
|
assert_equal :source, v.kind
|
58
58
|
assert_equal 1.0, v.priority
|
59
59
|
end
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def test_add_marks_with_both
|
63
63
|
@graph.vertices{|v| Source===v}.add_marks(:test2 => false) do |v|
|
64
64
|
v.set_mark(:test, true)
|
@@ -71,7 +71,7 @@ module Yargi
|
|
71
71
|
assert_equal 1.0, v.priority
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def test_to_dot
|
76
76
|
@graph.vertices{|v|Source===v}.add_marks(:label => '', :shape => 'diamond', :fixedsize => true, :width => 0.5)
|
77
77
|
@graph.vertices{|v|Sink===v}.add_marks(:label => '', :shape => 'doublecircle', :fixedsize => true, :width => 0.5)
|
@@ -85,12 +85,10 @@ module Yargi
|
|
85
85
|
begin
|
86
86
|
`dot -Tgif -o #{gitfile} #{dotfile}`
|
87
87
|
rescue => ex
|
88
|
-
$
|
88
|
+
$stderr.puts "dot test failed, probably not installed\n#{ex.message}"
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
|
94
92
|
end # class DigraphSetFeaturesSet
|
95
|
-
|
93
|
+
|
96
94
|
end
|
data/test/yargi/digraph_test.rb
CHANGED
@@ -3,15 +3,15 @@ require 'yargi'
|
|
3
3
|
|
4
4
|
module Yargi
|
5
5
|
class DigraphTest < Test::Unit::TestCase
|
6
|
-
|
6
|
+
|
7
7
|
module Until; end
|
8
8
|
module If; end
|
9
|
-
|
9
|
+
|
10
10
|
# Creates a digraph instance under @digraph
|
11
11
|
def setup
|
12
12
|
@digraph = Yargi::Digraph.new
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def test_to_vertices
|
16
16
|
untils = @digraph.add_n_vertices(5, Until)
|
17
17
|
ifs = @digraph.add_n_vertices(5, If)
|
@@ -25,7 +25,7 @@ module Yargi
|
|
25
25
|
assert_equal (untils+ifs).sort, @digraph.send(:to_vertices, [Until, If, untils[0]])
|
26
26
|
assert_equal (untils+ifs).sort, @digraph.send(:to_vertices, Until, If, untils[0])
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def test_to_edges
|
30
30
|
untils = @digraph.add_n_vertices(5, Until)
|
31
31
|
ifs = @digraph.add_n_vertices(5, If)
|
@@ -38,7 +38,7 @@ module Yargi
|
|
38
38
|
assert_equal untils_to_ifs, @digraph.send(:to_edges, Proc.new{|e| Until===e.source})
|
39
39
|
assert_equal ifs_to_untils, @digraph.send(:to_edges, Proc.new{|e| If===e.source})
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
# def test_to_dot_attributes
|
43
43
|
# hash = {:label => 'hello', :who => 'blambeau'}
|
44
44
|
# assert_equal 'label="hello" who="blambeau"', @digraph.send(:to_dot_attributes, hash)
|
@@ -47,11 +47,11 @@ module Yargi
|
|
47
47
|
# hash = {:label => 'hello', :pos => [[12, 14], [15, 17]]}
|
48
48
|
# assert_equal 'label="hello" pos="12,14 15,17"', @digraph.send(:to_dot_attributes, hash)
|
49
49
|
# end
|
50
|
-
|
50
|
+
|
51
51
|
def test_extend_returns_self_hypothese
|
52
52
|
assert_equal self, self.extend(Until)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def test_vertices
|
56
56
|
v1 = @digraph.add_vertex({:kind => :point})
|
57
57
|
v2 = @digraph.add_vertex({:kind => :point})
|
@@ -65,7 +65,7 @@ module Yargi
|
|
65
65
|
assert_equal VertexSet[v1, v2], @digraph.vertices {|v| v[:kind]==:point}
|
66
66
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def test_vertices_with_mods
|
70
70
|
untils = @digraph.add_n_vertices(5, Until)
|
71
71
|
ifs = @digraph.add_n_vertices(5, If)
|
@@ -73,7 +73,7 @@ module Yargi
|
|
73
73
|
assert_equal ifs, @digraph.vertices(If)
|
74
74
|
assert_equal (untils+ifs), @digraph.vertices(Yargi::NONE|Until|If)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
def test_vertices_with_both
|
78
78
|
untils = @digraph.add_n_vertices(5, Until)
|
79
79
|
ifs = @digraph.add_n_vertices(5, If)
|
@@ -84,7 +84,7 @@ module Yargi
|
|
84
84
|
v.index==0
|
85
85
|
end)
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def test_module_extended_vertices
|
89
89
|
v1 = @digraph.add_vertex(Until)
|
90
90
|
v2 = @digraph.add_vertex(If)
|
@@ -93,7 +93,7 @@ module Yargi
|
|
93
93
|
assert_equal VertexSet[v1], @digraph.vertices {|v| Until===v}
|
94
94
|
assert_equal VertexSet[v2], @digraph.vertices {|v| If===v}
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
def test_tag
|
98
98
|
v1, v2 = @digraph.add_n_vertices(2)
|
99
99
|
v1.tag(Until)
|
@@ -101,21 +101,21 @@ module Yargi
|
|
101
101
|
assert Until===v1
|
102
102
|
assert If===v2 and Until===v2
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def test_edges
|
106
106
|
v1, v2, v3 = @digraph.add_n_vertices(3)
|
107
107
|
e12, e23, e32, e21 = @digraph.connect_all([v1, v2], [v2, v3], [v3, v2], [v2, v1])
|
108
108
|
assert_equal EdgeSet[e12, e23], @digraph.edges {|e| e.index<=1}
|
109
109
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def test_each_vertex
|
113
113
|
v1, v2, v3 = @digraph.add_n_vertices(3)
|
114
114
|
seen = []
|
115
115
|
@digraph.each_vertex {|v| seen << v}
|
116
116
|
assert_equal [v1, v2, v3], seen
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
def test_each_vertex_with_filter
|
120
120
|
v1, v2, v3, v4, v5 = @digraph.add_n_vertices(5)
|
121
121
|
seen = []
|
@@ -127,7 +127,7 @@ module Yargi
|
|
127
127
|
@digraph.each_vertex(filter) {|v| seen << v}
|
128
128
|
assert_equal [v4, v5], seen
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
def test_each_edge
|
132
132
|
v1, v2, v3 = @digraph.add_n_vertices(3)
|
133
133
|
edges = @digraph.connect_all([v1, v2], [v2, v3], [v3, v2], [v2, v1])
|
@@ -135,7 +135,7 @@ module Yargi
|
|
135
135
|
@digraph.each_edge {|e| seen << e}
|
136
136
|
assert_equal edges, seen
|
137
137
|
end
|
138
|
-
|
138
|
+
|
139
139
|
def test_add_vertex
|
140
140
|
v1 = @digraph.add_vertex({:style => :begin})
|
141
141
|
assert_not_nil v1
|
@@ -143,7 +143,7 @@ module Yargi
|
|
143
143
|
assert_equal :begin, v1[:style]
|
144
144
|
assert_equal VertexSet[v1], @digraph.vertices
|
145
145
|
assert_equal 0, v1.index
|
146
|
-
|
146
|
+
|
147
147
|
v2 = @digraph.add_vertex({:style => :end})
|
148
148
|
assert_not_nil v2
|
149
149
|
assert_equal :end, v2[:style]
|
@@ -152,7 +152,7 @@ module Yargi
|
|
152
152
|
assert_equal 1, v2.index
|
153
153
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
154
154
|
end
|
155
|
-
|
155
|
+
|
156
156
|
def test_add_n_vertices
|
157
157
|
v1, v2, v3 = @digraph.add_n_vertices(3, {:hello => "world"})
|
158
158
|
assert_equal VertexSet[v1, v2, v3], @digraph.vertices
|
@@ -163,7 +163,7 @@ module Yargi
|
|
163
163
|
assert_equal ["world1", "world2", "world3"], @digraph.vertices.collect{|v| v[:hello]}
|
164
164
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
def test_add_n_vertices_with_block
|
168
168
|
vertices = @digraph.add_n_vertices(5, Until) do |v,i|
|
169
169
|
v.set_mark(:mark, i)
|
@@ -174,7 +174,7 @@ module Yargi
|
|
174
174
|
end
|
175
175
|
assert_equal [0, 1, 2, 3, 4], vertices.get_mark(:mark)
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
def test_connect
|
179
179
|
v1, v2 = @digraph.add_n_vertices(2)
|
180
180
|
edge = @digraph.connect(v1, v2, {:label => "hello"})
|
@@ -185,14 +185,14 @@ module Yargi
|
|
185
185
|
assert_equal v1, edge.source
|
186
186
|
assert_equal v2, edge.target
|
187
187
|
assert_equal EdgeSet[edge], @digraph.edges
|
188
|
-
|
188
|
+
|
189
189
|
assert_equal EdgeSet[], v1.in_edges
|
190
190
|
assert_equal EdgeSet[edge], v1.out_edges
|
191
191
|
assert_equal EdgeSet[], v2.out_edges
|
192
192
|
assert_equal EdgeSet[edge], v2.in_edges
|
193
193
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
def test_connect_all
|
197
197
|
v1, v2 = @digraph.add_n_vertices(2)
|
198
198
|
e1, e2 = @digraph.connect_all([v1, v2], [v2, v1])
|
@@ -206,7 +206,7 @@ module Yargi
|
|
206
206
|
assert_equal EdgeSet[e1], v1.out_edges
|
207
207
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
208
208
|
end
|
209
|
-
|
209
|
+
|
210
210
|
def test_connect_all_with_marks
|
211
211
|
v1, v2 = @digraph.add_n_vertices(2)
|
212
212
|
e1, e2 = @digraph.connect_all([v1, v2, {:hello => "world"}], [v2, v1, {:hello => "world"}])
|
@@ -224,7 +224,7 @@ module Yargi
|
|
224
224
|
assert_equal "world", e2[:hello]
|
225
225
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
226
226
|
end
|
227
|
-
|
227
|
+
|
228
228
|
def test_remove_edge
|
229
229
|
v1, v2 = @digraph.add_n_vertices(2)
|
230
230
|
edge = @digraph.connect(v1, v2)
|
@@ -235,7 +235,7 @@ module Yargi
|
|
235
235
|
assert_equal EdgeSet[], v1.out_edges
|
236
236
|
assert_equal EdgeSet[], v2.in_edges
|
237
237
|
assert_equal EdgeSet[], v2.out_edges
|
238
|
-
|
238
|
+
|
239
239
|
e1 = @digraph.connect(v1, v2)
|
240
240
|
e2 = @digraph.connect(v2, v1)
|
241
241
|
assert_equal VertexSet[v1, v2], @digraph.vertices
|
@@ -254,7 +254,7 @@ module Yargi
|
|
254
254
|
assert_equal 0, e2.index
|
255
255
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
256
256
|
end
|
257
|
-
|
257
|
+
|
258
258
|
def test_remove_edges
|
259
259
|
v1, v2, v3 = @digraph.add_n_vertices(3)
|
260
260
|
e12 = @digraph.connect(v1, v2)
|
@@ -268,7 +268,7 @@ module Yargi
|
|
268
268
|
assert_equal EdgeSet[], v.out_edges
|
269
269
|
end
|
270
270
|
assert_equal [-1], [e12, e23, e32, e21].collect {|e| e.index}.uniq
|
271
|
-
|
271
|
+
|
272
272
|
e12 = @digraph.connect(v1, v2)
|
273
273
|
e23 = @digraph.connect(v2, v3)
|
274
274
|
e32 = @digraph.connect(v3, v2)
|
@@ -283,7 +283,7 @@ module Yargi
|
|
283
283
|
assert_equal EdgeSet[e21], v1.in_edges
|
284
284
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
def test_remove_vertex
|
288
288
|
v1, v2, v3 = @digraph.add_n_vertices(3)
|
289
289
|
e12 = @digraph.connect(v1, v2)
|
@@ -299,7 +299,7 @@ module Yargi
|
|
299
299
|
assert_equal EdgeSet[e32], v2.in_edges
|
300
300
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
301
301
|
end
|
302
|
-
|
302
|
+
|
303
303
|
def test_reconnect
|
304
304
|
v1, v2 = @digraph.add_n_vertices(2)
|
305
305
|
edge = @digraph.connect(v1, v2)
|
@@ -312,13 +312,13 @@ module Yargi
|
|
312
312
|
assert_equal EdgeSet[edge], v2.out_edges
|
313
313
|
assert_nothing_raised { @digraph.send(:check_sanity) }
|
314
314
|
end
|
315
|
-
|
315
|
+
|
316
316
|
def test_connect_returns_flatten_set
|
317
317
|
sources = @digraph.add_n_vertices(5)
|
318
318
|
edges = @digraph.connect(sources, sources)
|
319
319
|
assert_equal 25, edges.length
|
320
320
|
end
|
321
|
-
|
321
|
+
|
322
322
|
# def test_remove_vertex_with_block
|
323
323
|
# v1, v2, v3 = @digraph.add_n_vertices(3)
|
324
324
|
# e12 = @digraph.connect(v1, v2)
|
@@ -341,7 +341,7 @@ module Yargi
|
|
341
341
|
# assert_equal [e23, e21], v2.out_edges
|
342
342
|
# assert_nothing_raised { @digraph.send(:check_sanity) }
|
343
343
|
# end
|
344
|
-
#
|
344
|
+
#
|
345
345
|
# def test_remove_vertex_with_block_using_edge_shortcuts
|
346
346
|
# v1, v2, v3 = @digraph.add_n_vertices(3)
|
347
347
|
# e12 = @digraph.connect(v1, v2)
|
@@ -364,6 +364,6 @@ module Yargi
|
|
364
364
|
# assert_equal [e23, e21], v2.out_edges
|
365
365
|
# assert_nothing_raised { @digraph.send(:check_sanity) }
|
366
366
|
# end
|
367
|
-
|
367
|
+
|
368
368
|
end
|
369
369
|
end
|
@@ -3,13 +3,13 @@ require 'yargi'
|
|
3
3
|
|
4
4
|
module Yargi
|
5
5
|
class Digraph
|
6
|
-
|
6
|
+
|
7
7
|
class VertexTest < Test::Unit::TestCase
|
8
|
-
|
8
|
+
|
9
9
|
module Center; end
|
10
10
|
module AtOne; end
|
11
11
|
module AtTwo; end
|
12
|
-
|
12
|
+
|
13
13
|
# Builds the star graph under @star
|
14
14
|
def setup
|
15
15
|
@star = Yargi::Digraph.new
|
@@ -22,13 +22,13 @@ module Yargi
|
|
22
22
|
end
|
23
23
|
@one_to_two = VertexSet.new(@one_to_two)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def test_in_and_out_edges
|
27
27
|
assert_equal EdgeSet[], @center.in_edges
|
28
28
|
assert_equal @center_to_one, @center.out_edges
|
29
29
|
assert_equal @center_to_one, @atone.collect{|v| v.in_edges}.flatten
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def test_in_adjacent
|
33
33
|
@atone.each {|v| assert_equal VertexSet[@center], v.in_adjacent}
|
34
34
|
@atone.each {|v| assert_equal VertexSet[@center], v.in_adjacent(Center)}
|
@@ -37,7 +37,7 @@ module Yargi
|
|
37
37
|
assert @atone.in_adjacent(AtOne).empty?
|
38
38
|
assert_equal VertexSet[@center], @atone.in_adjacent(Center)
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def test_out_adjacent
|
42
42
|
@atone.each_with_index {|v,i| assert_equal @attwo[i,1], v.out_adjacent}
|
43
43
|
@atone.each_with_index {|v,i| assert_equal @attwo[i,1], v.out_adjacent(AtTwo)}
|
@@ -46,7 +46,7 @@ module Yargi
|
|
46
46
|
assert @atone.out_adjacent(AtOne).empty?
|
47
47
|
assert_equal @attwo, @atone.out_adjacent(AtTwo)
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def test_adjacent
|
51
51
|
assert_equal @atone, @center.adjacent
|
52
52
|
assert_equal (@attwo+[@center]).sort, @atone.adjacent.sort
|
@@ -54,8 +54,8 @@ module Yargi
|
|
54
54
|
assert_equal @star.vertices, (@atone+[@center]).adjacent.sort
|
55
55
|
assert_equal @atone, (@atone+[@center]).adjacent(AtOne).sort
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
end # class VertexTest
|
59
|
-
|
59
|
+
|
60
60
|
end
|
61
61
|
end
|
@@ -2,7 +2,7 @@ require 'test/unit'
|
|
2
2
|
require 'yargi'
|
3
3
|
|
4
4
|
module Yargi
|
5
|
-
|
5
|
+
|
6
6
|
# Here to check that what's in the documentation is correct
|
7
7
|
class DocumentationTest < Test::Unit::TestCase
|
8
8
|
|
@@ -12,21 +12,21 @@ module Yargi
|
|
12
12
|
def test_README_example
|
13
13
|
# create a directed graph
|
14
14
|
digraph = Yargi::Digraph.new
|
15
|
-
|
15
|
+
|
16
16
|
# create 10 source and 5 sink vertices, tag them with user modules
|
17
17
|
sources = digraph.add_n_vertices(5, Source)
|
18
18
|
assert VertexSet===sources
|
19
|
-
|
19
|
+
|
20
20
|
# connect source to sink states
|
21
21
|
edges = digraph.connect(sources, sources)
|
22
22
|
assert EdgeSet===edges
|
23
|
-
|
23
|
+
|
24
24
|
# put some dot attributes
|
25
25
|
sources.add_marks(:shape => 'circle', :label => '')
|
26
26
|
edges.add_marks do |e|
|
27
27
|
{:label => "From #{e.source.index} to #{e.target.index}"}
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
# and print it
|
31
31
|
dir = File.expand_path(File.dirname(__FILE__))
|
32
32
|
dotfile = File.join(dir,"README-example.dot")
|
@@ -35,10 +35,10 @@ module Yargi
|
|
35
35
|
begin
|
36
36
|
`dot -Tgif -o #{gitfile} #{dotfile}`
|
37
37
|
rescue => ex
|
38
|
-
$
|
38
|
+
$stderr.puts "dot test failed, probably not installed\n#{ex.message}"
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
end # class DocumentationTest
|
43
|
-
|
43
|
+
|
44
44
|
end
|