rgl 0.5.1 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,25 +10,65 @@ class TestDot < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_to_dot_digraph
13
- graph = RGL::DirectedAdjacencyGraph[1, 2]
14
- dot = graph.to_dot_graph.to_s
15
-
16
- first_vertex_id = 1.object_id
17
- second_vertex_id = 2.object_id
18
-
19
- assert_match(dot, /\{[^}]*\}/) # {...}
20
- assert_match(dot, /#{first_vertex_id}\s*\[/) # node 1
21
- assert_match(dot, /label\s*=\s*1/) # node 1 label
22
- assert_match(dot, /#{second_vertex_id}\s*\[/) # node 2
23
- assert_match(dot, /label\s*=\s*2/) # node 2 label
24
- assert_match(dot, /#{first_vertex_id}\s*->\s*#{second_vertex_id}/) # edge
13
+ graph = RGL::DirectedAdjacencyGraph["a", "b"]
14
+
15
+ begin
16
+ dot = graph.to_dot_graph.to_s
17
+
18
+ first_vertex_id = "a"
19
+ second_vertex_id = "b"
20
+
21
+ assert_match(dot, /\{[^}]*\}/) # {...}
22
+ assert_match(dot, /#{first_vertex_id}\s*\[/) # node 1
23
+ assert_match(dot, /label\s*=\s*a/) # node 1 label
24
+ assert_match(dot, /#{second_vertex_id}\s*\[/) # node 2
25
+ assert_match(dot, /label\s*=\s*b/) # node 2 label
26
+ assert_match(dot, /#{first_vertex_id}\s*->\s*#{second_vertex_id}/) # edge
27
+ rescue
28
+ puts "Graphviz not installed?"
29
+ end
30
+ end
31
+
32
+ def test_to_dot_digraph_with_options
33
+ graph = RGL::DirectedAdjacencyGraph["a", "b"]
34
+
35
+ begin
36
+ edge_labels = {}
37
+ graph.each_edge do |b, e|
38
+ key = "#{b}-#{e}"
39
+ edge_labels[key] = "#{b} to #{e}"
40
+ end
41
+
42
+ vertex_fontcolors = {'a' => 'green', 'b' => 'blue'}
43
+ vertex_fontcolor_setting = Proc.new{|v| vertex_fontcolors[v]}
44
+ vertex_settings = {'fontcolor' => vertex_fontcolor_setting, 'fontsize' => 12}
45
+
46
+ edge_label_setting = Proc.new{|b, e| edge_labels["#{b}-#{e}"]}
47
+ edge_settings = {'color' => 'red', 'label' => edge_label_setting}
48
+ dot_options = {'edge' => edge_settings,'vertex' => vertex_settings}
49
+ dot = graph.to_dot_graph(dot_options).to_s
50
+
51
+ assert_match(dot, /a \[\n\s*fontcolor = green,\n\s*fontsize = 12,\n\s*label = a\n\s*/)
52
+ assert_match(dot, /b \[\n\s*fontcolor = blue,\n\s*fontsize = 12,\n\s*label = b\n\s*/)
53
+ assert_match(dot, /a -> b \[\n\s*color = red,\n\s*fontsize = 8,\n\s*label = \"a to b\"\n/)
54
+ rescue
55
+ puts "Graphviz not installed?"
56
+ end
25
57
  end
26
58
 
27
59
  def test_to_dot_graph
28
- graph = RGL::AdjacencyGraph[1, 2]
60
+ graph = RGL::AdjacencyGraph["a", "b"]
29
61
  def graph.vertex_label(v)
30
62
  "label-"+v.to_s
31
63
  end
32
- dot = graph.write_to_graphic_file
64
+
65
+ def graph.vertex_id(v)
66
+ "id-"+v.to_s
67
+ end
68
+ begin
69
+ graph.write_to_graphic_file
70
+ rescue
71
+ puts "Graphviz not installed?"
72
+ end
33
73
  end
34
74
  end
@@ -63,6 +63,11 @@ class TestGraph < Test::Unit::TestCase
63
63
  assert_equal edges, @dg1.edges
64
64
  end
65
65
 
66
+ # Test for issue #22
67
+ def test_edges_to_s
68
+ assert_equal @dg1.edges.sort.to_s, "[(1-2), (1-6), (2-3), (2-4), (4-5), (6-4)]"
69
+ end
70
+
66
71
  def test_not_implemented
67
72
  graph = NotImplementedGraph.new
68
73
  assert_raise(NotImplementedError) { graph.each_vertex }
@@ -31,7 +31,7 @@ class TestGraphXML < Test::Unit::TestCase
31
31
  name, nnodes, nedges = $1, $2.to_i, $3.to_i
32
32
  end
33
33
  if name && /directed: (\w+).*acyclic: (\w+).*connected: (\w+).*biconnected: (\w+)\s+/ =~ line
34
- directed, acyclic, connected, biconnected = $1, $2, $3, $4
34
+ directed, acyclic, connected = $1, $2, $3
35
35
  File.open(NORTH_DIR + name + '.graphml') {
36
36
  |file|
37
37
  print '.'; $stdout.flush
@@ -44,12 +44,6 @@ class TestGraphXML < Test::Unit::TestCase
44
44
  num_comp = 0
45
45
  graph.to_undirected.each_connected_component { |x| num_comp += 1 }
46
46
  assert_equal(connected, (num_comp == 1).to_s)
47
-
48
- # if graph.directed?
49
- # num_comp = graph.strongly_connected_components.num_comp
50
- # #puts num_comp
51
- # assert_equal(biconnected, (num_comp == 1).to_s)
52
- # end
53
47
  }
54
48
  end
55
49
  }
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ require 'rgl/adjacency'
6
+ require 'rgl/path'
7
+
8
+ class TestPath < Test::Unit::TestCase
9
+ include RGL
10
+
11
+ def setup
12
+ edges = [[1, 2], [2, 3], [2, 4], [4, 5], [6, 4], [1, 6]]
13
+ @directed_graph, @undirected_graph =
14
+ [DirectedAdjacencyGraph, AdjacencyGraph].map do |klass|
15
+ graph = klass.new
16
+ graph.add_edges(*edges)
17
+ graph
18
+ end
19
+ end
20
+
21
+ def test_path_for_directed_graph
22
+ assert(@directed_graph.path?(1, 5))
23
+ end
24
+
25
+ def test_path_for_undirected_graph
26
+ assert(@undirected_graph.path?(1, 5))
27
+ end
28
+
29
+ def test_inverse_path_for_directed_graph
30
+ assert_equal(@directed_graph.path?(3, 1), false)
31
+ end
32
+
33
+ def test_inverse_path_for_undirected_graph
34
+ assert(@undirected_graph.path?(3, 1))
35
+ end
36
+
37
+ def test_path_for_directed_graph_wrong_source
38
+ assert_equal(@directed_graph.path?(0, 1), false)
39
+ end
40
+
41
+ def test_path_for_undirected_graph_wrong_source
42
+ assert_equal(@undirected_graph.path?(0, 1), false)
43
+ end
44
+
45
+ def test_path_for_directed_graph_wrong_target
46
+ assert_equal(@directed_graph.path?(4, 0), false)
47
+ end
48
+
49
+ def test_path_for_undirected_graph_wrong_target
50
+ assert_equal(@undirected_graph.path?(4, 0), false)
51
+ end
52
+ end
@@ -1,3 +1,6 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require 'rubygems'
2
5
  require 'test/unit'
3
6
 
@@ -218,4 +218,30 @@ END
218
218
  dg.depth_first_search(vis) { |x| }
219
219
  assert_equal("(1 (2 (3 3)(4 (5 5) 4) 2)(6 6) 1)(10 (11 11) 10)", a)
220
220
  end
221
+
222
+ def test_bfs_stream_protocol
223
+ it = @dg.bfs_iterator(1)
224
+ assert_true(it.at_beginning?)
225
+
226
+ it.set_to_end()
227
+ assert_true(it.at_end?)
228
+
229
+ it.set_to_begin()
230
+ assert_true(it.at_beginning?)
231
+
232
+ assert_equal(it.to_a(), [1, 2, 6, 3, 4, 5])
233
+ end
234
+
235
+ def test_dfs_stream_protocol
236
+ it = @dg.dfs_iterator(1)
237
+ assert_true(it.at_beginning?)
238
+
239
+ it.set_to_end()
240
+ assert_true(it.at_end?)
241
+
242
+ it.set_to_begin()
243
+ assert_true(it.at_beginning?)
244
+
245
+ assert_equal(it.to_a(), [1, 6, 4, 5, 2, 3])
246
+ end
221
247
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
5
- prerelease:
4
+ version: 0.5.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Horst Duchene
@@ -10,86 +9,76 @@ authors:
10
9
  autorequire: rgl/base
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2015-07-25 00:00:00.000000000 Z
12
+ date: 2020-12-19 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: stream
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ~>
18
+ - - "~>"
21
19
  - !ruby/object:Gem::Version
22
- version: 0.5.0
20
+ version: 0.5.3
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ~>
25
+ - - "~>"
29
26
  - !ruby/object:Gem::Version
30
- version: 0.5.0
27
+ version: 0.5.3
31
28
  - !ruby/object:Gem::Dependency
32
- name: algorithms
29
+ name: lazy_priority_queue
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ~>
32
+ - - "~>"
37
33
  - !ruby/object:Gem::Version
38
- version: 0.6.1
34
+ version: 0.1.0
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ~>
39
+ - - "~>"
45
40
  - !ruby/object:Gem::Version
46
- version: 0.6.1
41
+ version: 0.1.0
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: rake
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - ">="
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - ">="
61
54
  - !ruby/object:Gem::Version
62
55
  version: '0'
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: yard
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - ">="
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - ">="
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: test-unit
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - ">="
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - ">="
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  description: RGL is a framework for graph data structures and algorithms
@@ -97,168 +86,160 @@ email: monora@gmail.com
97
86
  executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files:
100
- - README.rdoc
89
+ - README.md
101
90
  files:
102
- - lib/rgl/dijkstra.rb
103
- - lib/rgl/edmonds_karp.rb
104
- - lib/rgl/graphxml.rb
105
- - lib/rgl/edge_properties_map.rb
106
- - lib/rgl/transitiv_closure.rb
107
- - lib/rgl/condensation.rb
108
- - lib/rgl/topsort.rb
109
- - lib/rgl/path_builder.rb
110
- - lib/rgl/bellman_ford.rb
111
- - lib/rgl/graph_visitor.rb
112
- - lib/rgl/bidirectional.rb
113
- - lib/rgl/rdot.rb
114
- - lib/rgl/prim.rb
115
- - lib/rgl/adjacency.rb
116
- - lib/rgl/implicit.rb
117
- - lib/rgl/traversal.rb
118
- - lib/rgl/base.rb
119
- - lib/rgl/dot.rb
120
- - lib/rgl/graph_iterator.rb
121
- - lib/rgl/enumerable_ext.rb
122
- - lib/rgl/dijkstra_visitor.rb
123
- - lib/rgl/mutable.rb
124
- - lib/rgl/connected_components.rb
125
- - lib/rgl/transitivity.rb
126
- - lib/rgl/graph_wrapper.rb
127
- - lib/rgl/bipartite.rb
128
91
  - ChangeLog
129
- - examples/images/module_graph.jpg
130
- - examples/images/example.jpg
131
- - examples/images/rgl_modules.png
132
- - examples/insel_der_tausend_gefahren.rb
133
- - examples/rdep-rgl.rb
134
- - examples/north2.rb
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
135
95
  - examples/canvas.rb
96
+ - examples/examples.rb
97
+ - examples/insel_der_tausend_gefahren.rb
136
98
  - examples/north.rb
137
- - examples/north/g.10.45.graphml
138
- - examples/north/g.10.6.graphml
139
- - examples/north/g.10.56.graphml
140
- - examples/north/g.10.8.graphml
141
- - examples/north/g.10.29.graphml
142
- - examples/north/g.10.30.graphml
143
- - examples/north/g.10.37.graphml
144
99
  - examples/north/Graph.log
145
- - examples/north/g.10.20.graphml
146
- - examples/north/g.10.9.graphml
147
- - examples/north/g.10.74.graphml
148
- - examples/north/g.10.61.graphml
149
- - examples/north/g.12.8.graphml
150
- - examples/north/g.10.71.graphml
151
- - examples/north/g.10.7.graphml
152
- - examples/north/g.10.38.graphml
100
+ - examples/north/g.10.0.graphml
101
+ - examples/north/g.10.1.graphml
102
+ - examples/north/g.10.11.graphml
103
+ - examples/north/g.10.12.graphml
104
+ - examples/north/g.10.13.graphml
105
+ - examples/north/g.10.14.graphml
153
106
  - examples/north/g.10.15.graphml
154
- - examples/north/g.10.50.graphml
107
+ - examples/north/g.10.16.graphml
108
+ - examples/north/g.10.17.graphml
155
109
  - examples/north/g.10.19.graphml
156
- - examples/north/g.10.62.graphml
110
+ - examples/north/g.10.2.graphml
111
+ - examples/north/g.10.20.graphml
112
+ - examples/north/g.10.22.graphml
113
+ - examples/north/g.10.24.graphml
114
+ - examples/north/g.10.25.graphml
115
+ - examples/north/g.10.27.graphml
116
+ - examples/north/g.10.28.graphml
117
+ - examples/north/g.10.29.graphml
118
+ - examples/north/g.10.3.graphml
119
+ - examples/north/g.10.30.graphml
157
120
  - examples/north/g.10.31.graphml
158
- - examples/north/g.10.92.graphml
159
- - examples/north/g.10.88.graphml
160
- - examples/north/g.10.91.graphml
161
- - examples/north/g.10.93.graphml
162
- - examples/north/g.10.16.graphml
163
- - examples/north/g.10.90.graphml
164
121
  - examples/north/g.10.34.graphml
165
- - examples/north/g.10.0.graphml
166
- - examples/north/g.10.27.graphml
167
- - examples/north/g.10.82.graphml
168
- - examples/north/g.10.5.graphml
169
- - examples/north/g.10.17.graphml
122
+ - examples/north/g.10.37.graphml
123
+ - examples/north/g.10.38.graphml
170
124
  - examples/north/g.10.39.graphml
171
- - examples/north/g.10.94.graphml
125
+ - examples/north/g.10.4.graphml
126
+ - examples/north/g.10.40.graphml
172
127
  - examples/north/g.10.41.graphml
173
- - examples/north/g.10.70.graphml
174
- - examples/north/g.10.68.graphml
175
- - examples/north/g.10.72.graphml
176
- - examples/north/g.10.86.graphml
177
- - examples/north/g.10.79.graphml
178
- - examples/north/g.10.85.graphml
179
128
  - examples/north/g.10.42.graphml
180
- - examples/north/g.10.83.graphml
181
- - examples/north/g.10.24.graphml
182
- - examples/north/g.10.13.graphml
183
- - examples/north/g.10.75.graphml
184
- - examples/north/g.10.22.graphml
185
- - examples/north/g.10.89.graphml
186
- - examples/north/g.10.12.graphml
129
+ - examples/north/g.10.45.graphml
187
130
  - examples/north/g.10.46.graphml
188
- - examples/north/g.10.40.graphml
189
- - examples/north/g.10.3.graphml
190
- - examples/north/g.10.80.graphml
191
- - examples/north/g.10.11.graphml
131
+ - examples/north/g.10.5.graphml
132
+ - examples/north/g.10.50.graphml
133
+ - examples/north/g.10.56.graphml
192
134
  - examples/north/g.10.57.graphml
135
+ - examples/north/g.10.58.graphml
136
+ - examples/north/g.10.6.graphml
137
+ - examples/north/g.10.60.graphml
138
+ - examples/north/g.10.61.graphml
139
+ - examples/north/g.10.62.graphml
140
+ - examples/north/g.10.68.graphml
193
141
  - examples/north/g.10.69.graphml
194
- - examples/north/g.10.4.graphml
142
+ - examples/north/g.10.7.graphml
143
+ - examples/north/g.10.70.graphml
144
+ - examples/north/g.10.71.graphml
145
+ - examples/north/g.10.72.graphml
146
+ - examples/north/g.10.74.graphml
147
+ - examples/north/g.10.75.graphml
195
148
  - examples/north/g.10.78.graphml
149
+ - examples/north/g.10.79.graphml
150
+ - examples/north/g.10.8.graphml
151
+ - examples/north/g.10.80.graphml
152
+ - examples/north/g.10.82.graphml
153
+ - examples/north/g.10.83.graphml
154
+ - examples/north/g.10.85.graphml
155
+ - examples/north/g.10.86.graphml
156
+ - examples/north/g.10.88.graphml
157
+ - examples/north/g.10.89.graphml
158
+ - examples/north/g.10.9.graphml
159
+ - examples/north/g.10.90.graphml
160
+ - examples/north/g.10.91.graphml
161
+ - examples/north/g.10.92.graphml
162
+ - examples/north/g.10.93.graphml
163
+ - examples/north/g.10.94.graphml
164
+ - examples/north/g.12.8.graphml
196
165
  - examples/north/g.14.9.graphml
197
- - examples/north/g.10.58.graphml
198
- - examples/north/g.10.60.graphml
199
- - examples/north/g.10.1.graphml
200
- - examples/north/g.10.25.graphml
201
- - examples/north/g.10.14.graphml
202
- - examples/north/g.10.28.graphml
203
- - examples/north/g.10.2.graphml
204
- - examples/examples.rb
205
- - Gemfile
206
- - README.rdoc
207
- - Rakefile
166
+ - examples/north2.rb
167
+ - examples/rdep-rgl.rb
168
+ - examples/unix.dot
169
+ - lib/rgl/adjacency.rb
170
+ - lib/rgl/base.rb
171
+ - lib/rgl/bellman_ford.rb
172
+ - lib/rgl/bidirectional.rb
173
+ - lib/rgl/bipartite.rb
174
+ - lib/rgl/condensation.rb
175
+ - lib/rgl/connected_components.rb
176
+ - lib/rgl/dijkstra.rb
177
+ - lib/rgl/dijkstra_visitor.rb
178
+ - lib/rgl/dot.rb
179
+ - lib/rgl/edge_properties_map.rb
180
+ - lib/rgl/edmonds_karp.rb
181
+ - lib/rgl/graph_iterator.rb
182
+ - lib/rgl/graph_visitor.rb
183
+ - lib/rgl/graph_wrapper.rb
184
+ - lib/rgl/graphxml.rb
185
+ - lib/rgl/implicit.rb
186
+ - lib/rgl/mutable.rb
187
+ - lib/rgl/path.rb
188
+ - lib/rgl/path_builder.rb
189
+ - lib/rgl/prim.rb
190
+ - lib/rgl/rdot.rb
191
+ - lib/rgl/topsort.rb
192
+ - lib/rgl/transitiv_closure.rb
193
+ - lib/rgl/transitivity.rb
194
+ - lib/rgl/traversal.rb
208
195
  - rakelib/dep_graph.rake
196
+ - test/bellman_ford_test.rb
197
+ - test/bipartite_test.rb
198
+ - test/components_test.rb
199
+ - test/cycles_test.rb
200
+ - test/dijkstra_issue24_test.rb
209
201
  - test/dijkstra_test.rb
210
- - test/prim_test.rb
202
+ - test/directed_graph_test.rb
211
203
  - test/dot_test.rb
212
- - test/graph_xml_test.rb
204
+ - test/edge_properties_map_test.rb
213
205
  - test/edge_test.rb
214
206
  - test/edmonds_karp_test.rb
215
- - test/traversal_test.rb
216
- - test/edge_properties_map_test.rb
217
207
  - test/graph_test.rb
218
- - test/undirected_graph_test.rb
219
- - test/components_test.rb
208
+ - test/graph_xml_test.rb
220
209
  - test/implicit_test.rb
221
- - test/directed_graph_test.rb
222
- - test/bellman_ford_test.rb
210
+ - test/path_test.rb
211
+ - test/prim_test.rb
223
212
  - test/rdot_test.rb
224
- - test/cycles_test.rb
225
213
  - test/test_helper.rb
226
214
  - test/transitivity_test.rb
227
- - test/bipartite_test.rb
215
+ - test/traversal_test.rb
216
+ - test/undirected_graph_test.rb
228
217
  homepage: https://github.com/monora/rgl
229
- licenses: []
230
- post_install_message:
218
+ licenses:
219
+ - ruby
220
+ metadata: {}
221
+ post_install_message:
231
222
  rdoc_options:
232
- - --title
223
+ - "--title"
233
224
  - RGL - Ruby Graph Library
234
- - --main
235
- - README.rdoc
236
- - --line-numbers
225
+ - "--main"
226
+ - README.md
227
+ - "--line-numbers"
237
228
  require_paths:
238
229
  - lib
239
230
  required_ruby_version: !ruby/object:Gem::Requirement
240
- none: false
241
231
  requirements:
242
- - - ! '>='
232
+ - - ">="
243
233
  - !ruby/object:Gem::Version
244
234
  version: '0'
245
- segments:
246
- - 0
247
- hash: 900116365
248
235
  required_rubygems_version: !ruby/object:Gem::Requirement
249
- none: false
250
236
  requirements:
251
- - - ! '>='
237
+ - - ">="
252
238
  - !ruby/object:Gem::Version
253
239
  version: '0'
254
- segments:
255
- - 0
256
- hash: 900116365
257
240
  requirements: []
258
- rubyforge_project:
259
- rubygems_version: 1.8.23
260
- signing_key:
261
- specification_version: 3
241
+ rubygems_version: 3.0.6
242
+ signing_key:
243
+ specification_version: 4
262
244
  summary: Ruby Graph Library
263
245
  test_files: []
264
- has_rdoc: true