graphs 0.1.8-x86-linux → 0.1.9-x86-linux

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.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ &X���3��+���^�h��i5K�ޅ��B�J+%6�rS��ʵxI>#
data/lib/graph.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #! /usr/bin/env ruby
1
2
  # -*- coding: UTF-8 -*-
2
3
 
3
4
  require 'yaml'
@@ -54,7 +55,9 @@ class Graph
54
55
  attr_accessor :attrs
55
56
 
56
57
  def initialize(attrs=nil)
57
- @attrs = attrs || {}
58
+
59
+ @attrs = attrs.is_a?(Node) ? attrs.attrs : attrs || {}
60
+
58
61
  end
59
62
 
60
63
  # compare two nodes
@@ -86,7 +89,7 @@ class Graph
86
89
  attr_accessor :attrs
87
90
 
88
91
  def initialize(attrs=nil)
89
- @attrs = attrs || {}
92
+ @attrs = attrs.is_a?(Edge) ? attrs.attrs : attrs || {}
90
93
  end
91
94
 
92
95
  # compare two edges
@@ -222,8 +225,8 @@ class Graph
222
225
  return nil
223
226
  end
224
227
 
225
- nodes = (@nodes + other.nodes) - (@nodes & other.nodes)
226
- edges = (@edges + other.edges) - (@edges & other.edges)
228
+ nodes = (@nodes - other.nodes) + (other.nodes - @nodes)
229
+ edges = (@edges - other.edges) + (other.edges - @edges)
227
230
 
228
231
  Graph.new(nodes, edges)
229
232
  end
@@ -278,7 +281,7 @@ class Graph
278
281
  # Return true if the Graph is directed.
279
282
  # @see Graph.attrs
280
283
  def directed?()
281
- self.attrs[:directed]
284
+ !!self.attrs[:directed]
282
285
  end
283
286
 
284
287
  # Clone the current graph. All nodes and edges are also cloned. A new Graph
@@ -405,23 +408,19 @@ class Graph
405
408
  # @param n [Node,String] A node with a 'label' or :label attribute, or a string
406
409
  def get_neighbours(n)
407
410
 
408
- label = Graph::get_label(n)
411
+ label = Graph::get_label n
409
412
  neighbours = NodeArray.new []
410
413
 
411
414
  self.edges.each do |e|
412
415
 
413
- begin
414
-
415
- l1 = e.node1
416
- l2 = e.node2
417
-
418
- rescue NoMethodError; next; end
416
+ l1 = e[:node1] || e['node1']
417
+ l2 = e[:node2] || e['node2']
419
418
 
420
419
  if l2 && l1 == label
421
420
 
422
421
  n2 = self.get_node l2
423
422
 
424
- unless neighbours.include?(l2)
423
+ unless n2.nil? || neighbours.include?(n2)
425
424
 
426
425
  neighbours.push(n2)
427
426
 
@@ -433,7 +432,7 @@ class Graph
433
432
 
434
433
  n1 = self.get_node l1
435
434
 
436
- unless neighbours.include?(n1)
435
+ unless n1.nil? || neighbours.include?(n1)
437
436
 
438
437
  neighbours.push(n1)
439
438
 
data/lib/graphs/gdf.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #! /usr/bin/env ruby
1
2
  # -*- coding: UTF-8 -*-
2
3
 
3
4
  require_relative '../graph'
data/lib/graphs/json.rb CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby1.9.1
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
4
  require 'json'
data/tests/edge_tests.rb CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby1.9.1
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
4
  class Edge_test < Test::Unit::TestCase
@@ -43,4 +43,50 @@ class Edge_test < Test::Unit::TestCase
43
43
  assert_equal(true, e.update({}).is_a?(Graph::Edge))
44
44
  end
45
45
 
46
+ def test_edge_init_with_another_edge
47
+
48
+ e = Graph::Edge.new({ :foo => 'bar' })
49
+
50
+ assert_equal( e, Graph::Edge.new(e) )
51
+
52
+ end
53
+
54
+ end
55
+
56
+ class EdgeArray_test < Test::Unit::TestCase
57
+
58
+ def test_edgearray_push_edge
59
+
60
+ e = Graph::Edge.new({ :foo => 42 })
61
+ ea = Graph::EdgeArray.new([])
62
+
63
+ ea.push(e)
64
+
65
+ assert_equal(e, ea[0])
66
+
67
+ end
68
+
69
+ def test_edgearray_push_hash
70
+
71
+ e = { :foo => 42 }
72
+ ea = Graph::EdgeArray.new([])
73
+
74
+ ea.push(e)
75
+
76
+ assert_equal(Graph::Edge.new(e), ea[0])
77
+
78
+ end
79
+
80
+ def test_edgearray_push_no_edge_nor_hash
81
+
82
+ ea = Graph::EdgeArray.new([])
83
+
84
+ assert_raise(TypeError) do
85
+
86
+ ea.push(42)
87
+
88
+ end
89
+
90
+ end
91
+
46
92
  end
data/tests/gdf_tests.rb CHANGED
@@ -1,6 +1,5 @@
1
- #! /usr/bin/ruby1.9.1
2
-
3
- require_relative '../lib/graphs/gdf'
1
+ #! /usr/bin/env ruby
2
+ # -*- coding: UTF-8 -*-
4
3
 
5
4
  module Utils
6
5
  def self.get_sample_graph
@@ -215,4 +214,11 @@ class GDF_test < Test::Unit::TestCase
215
214
  assert_equal("nodedef>n INT\n9999999999999999\nedgedef>", gdf)
216
215
 
217
216
  end
217
+
218
+ def test_unparse_float_field
219
+ g = Graph.new([{ 'n' => 3.14 }])
220
+ gdf = GDF::unparse(g)
221
+
222
+ assert_equal("nodedef>n FLOAT\n3.14\nedgedef>", gdf)
223
+ end
218
224
  end
data/tests/graph_tests.rb CHANGED
@@ -1,10 +1,6 @@
1
- #! /usr/bin/ruby1.9.1
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
- require 'test/unit'
5
- require 'yaml'
6
- require_relative '../lib/graph'
7
-
8
4
  class Graph_test < Test::Unit::TestCase
9
5
 
10
6
  def setup
@@ -184,6 +180,19 @@ class Graph_test < Test::Unit::TestCase
184
180
  assert_equal(true, g1==g2)
185
181
  end
186
182
 
183
+ def test_equal_graph_and_non_graph
184
+
185
+ g = Graph.new
186
+
187
+ assert_equal(false, g==[])
188
+ assert_equal(false, g=={})
189
+ assert_equal(false, g==0)
190
+ assert_equal(false, g==false)
191
+ assert_equal(false, g==nil)
192
+ assert_equal(false, g==Graph::Node.new)
193
+
194
+ end
195
+
187
196
  # == Graph::NodeArray#set_default == #
188
197
 
189
198
  def test_nodearray_set_default_unexisting_property
@@ -384,6 +393,17 @@ class Graph_test < Test::Unit::TestCase
384
393
  assert_equal(g2, g+g)
385
394
  end
386
395
 
396
+ def test_graph_plus_non_graph
397
+
398
+ g = @@sample_graph
399
+
400
+ assert_equal(nil, g+42)
401
+ assert_equal(nil, g+[])
402
+ assert_equal(nil, g+{})
403
+ assert_equal(nil, g+Graph::Node.new)
404
+
405
+ end
406
+
387
407
  # == Graph#| == #
388
408
 
389
409
  def test_empty_graph_OR_empty_graph
@@ -413,6 +433,17 @@ class Graph_test < Test::Unit::TestCase
413
433
  assert_equal(g4, g2|g1)
414
434
  end
415
435
 
436
+ def test_graph_OR_non_graph
437
+
438
+ g = @@sample_graph
439
+
440
+ assert_equal(nil, g|42)
441
+ assert_equal(nil, g|[])
442
+ assert_equal(nil, g|{})
443
+ assert_equal(nil, g|Graph::Node.new)
444
+
445
+ end
446
+
416
447
  # == Graph#- == #
417
448
 
418
449
  def test_empty_graph_minus_empty_graph
@@ -437,6 +468,17 @@ class Graph_test < Test::Unit::TestCase
437
468
  assert_equal(@@empty, g-g)
438
469
  end
439
470
 
471
+ def test_graph_minus_non_graph
472
+
473
+ g = @@sample_graph
474
+
475
+ assert_equal(nil, g-42)
476
+ assert_equal(nil, g-[])
477
+ assert_equal(nil, g-{})
478
+ assert_equal(nil, g-Graph::Node.new)
479
+
480
+ end
481
+
440
482
  # == Graph#not == #
441
483
 
442
484
  def test_empty_graph_NOT_empty_graph
@@ -601,10 +643,13 @@ class Graph_test < Test::Unit::TestCase
601
643
  def test_graph_get_neighbours_undirected_graph
602
644
 
603
645
  g = @@sample_graph
646
+ g.attrs[:directed] = false
604
647
 
605
- n = g.get_neighbours 'foo'
648
+ n1 = g.get_neighbours 'chuck'
649
+ n2 = g.get_neighbours 'foo'
606
650
 
607
- assert_equal([ 'bar', 'chuck' ], n.map { |m| m.label })
651
+ assert_equal([ 'bar', 'foo' ], n1.map { |m| m.label })
652
+ assert_equal([ 'bar', 'chuck' ], n2.map { |m| m.label })
608
653
 
609
654
  end
610
655
 
@@ -616,7 +661,24 @@ class Graph_test < Test::Unit::TestCase
616
661
  assert_equal([ 'bar' ], n.map { |m| m.label })
617
662
 
618
663
  n = g.get_neighbours 'bar'
619
- assert_equal([], n.map { |m| m.label })
664
+ assert_equal([], n)
665
+
666
+ end
667
+
668
+ def test_graph_get_neighbours_bad_edges
669
+
670
+ g = Graph.new(
671
+ [ { :label => 'foo' },
672
+ { :label => 'bar' },
673
+ { :label => 'moo' }],
674
+
675
+ [ { :node1 => 'foo' }, # missing :node2 attr
676
+ { :node1 => 'foo', :node2 => 'moo' }])
677
+
678
+ n = g.get_neighbours 'foo'
679
+
680
+ assert_equal(1, n.length)
681
+ assert_equal('moo', n[0].label)
620
682
 
621
683
  end
622
684
 
data/tests/json_tests.rb CHANGED
@@ -1,8 +1,6 @@
1
- #! /usr/bin/ruby1.9.1
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
- require_relative '../lib/graphs/json'
5
-
6
4
  module JSONUtils
7
5
  def self.get_sample_graph
8
6
  @@json
data/tests/node_tests.rb CHANGED
@@ -1,4 +1,4 @@
1
- #! /usr/bin/ruby1.9.1
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
4
  class Node_test < Test::Unit::TestCase
@@ -92,4 +92,50 @@ class Node_test < Test::Unit::TestCase
92
92
  assert_equal(true, n.update({}).is_a?(Graph::Node))
93
93
  end
94
94
 
95
+ def test_node_init_with_another_node
96
+
97
+ n = Graph::Node.new({ :foo => 'bar' })
98
+
99
+ assert_equal( n, Graph::Node.new(n) )
100
+
101
+ end
102
+
103
+ end
104
+
105
+ class NodeArray_test < Test::Unit::TestCase
106
+
107
+ def test_nodearray_push_node
108
+
109
+ n = Graph::Node.new({ :foo => 42 })
110
+ na = Graph::NodeArray.new([])
111
+
112
+ na.push(n)
113
+
114
+ assert_equal(n, na[0])
115
+
116
+ end
117
+
118
+ def test_nodearray_push_hash
119
+
120
+ n = { :foo => 42 }
121
+ na = Graph::NodeArray.new([])
122
+
123
+ na.push(n)
124
+
125
+ assert_equal(Graph::Node.new(n), na[0])
126
+
127
+ end
128
+
129
+ def test_nodearray_push_no_node_nor_hash
130
+
131
+ na = Graph::NodeArray.new([])
132
+
133
+ assert_raise(TypeError) do
134
+
135
+ na.push(42)
136
+
137
+ end
138
+
139
+ end
140
+
95
141
  end
data/tests/tests.rb CHANGED
@@ -1,11 +1,20 @@
1
- #! /usr/bin/ruby1.9.1
1
+ #! /usr/bin/env ruby
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
4
  require 'test/unit'
5
5
  require 'tempfile'
6
+ require 'simplecov'
7
+
8
+ test_dir = File.expand_path( File.dirname(__FILE__) )
9
+
10
+ SimpleCov.start { add_filter '/tests/' } if ENV['COVERAGE']
11
+
6
12
  require_relative '../lib/graph'
13
+ require_relative '../lib/graphs/gdf'
14
+ require_relative '../lib/graphs/json'
7
15
 
8
- for t in Dir.glob( File.join( File.expand_path( File.dirname(__FILE__) ), '*_tests.rb' ) )
16
+ for t in Dir.glob( File.join( test_dir, '*_tests.rb' ) )
9
17
  require t
10
18
  end
11
19
 
20
+ exit Test::Unit::AutoRunner.run
metadata CHANGED
@@ -1,15 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  prerelease:
6
6
  platform: x86-linux
7
7
  authors:
8
8
  - Baptiste Fontaine
9
9
  autorequire:
10
10
  bindir: bin
11
- cert_chain: []
12
- date: 2013-02-13 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURMakNDQWhhZ0F3SUJB
14
+ Z0lCQURBTkJna3Foa2lHOXcwQkFRVUZBREE5TVJBd0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+ T09xVzQ4bHVjOWhWL2tRa1BWbjA0UEFFWTdGdDVadDEzVXhEL0syR3pLUWNJ
32
+ UGxoang4c3g3ZTQ4d3VFMkEKcDZmeWt5OTlaSWg1NlExbUVlZnQwQXJUd0Mr
33
+ NE5uanFzYWlueXgrYzNCelVKMEFTYVpQSkdYaGRwaGsvTWtYNApXSDV6Y09r
34
+ NXpjMGx3cmluUWtWb1lDWFI1YUhmMlNWbmFsaVlLRFlzVE16R1BVeE53ZitJ
35
+ TjBpTm9NcUJtWEVwCk81VkdnRjlYQ1B1SmE4UEpuWDBMMEZyeS9mSk0rVm83
36
+ WWxFQ2dSakhId3lNanpGeVJVUkRtOElkUzVianc1ZUoKWjVWZ1VBQ2NjYWVL
37
+ YmxueWlrRlRYeTE2bUJubER6MUlPeG9ENFBmeFROWC94b3I0aGRmM1BFN20x
38
+ K3gvY0NHMApReE09Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
39
+ date: 2013-03-24 00:00:00.000000000 Z
13
40
  dependencies: []
14
41
  description: Provide functions to (un)parse GDF/JSON files and generate graphs
15
42
  email: batifon@yahoo.fr
@@ -25,7 +52,6 @@ files:
25
52
  - tests/tests.rb
26
53
  - tests/node_tests.rb
27
54
  - tests/gdf_tests.rb
28
- - tests/gexf_tests.rb
29
55
  - tests/json_tests.rb
30
56
  homepage: https://github.com/bfontaine/Graphs.rb
31
57
  licenses:
@@ -48,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
74
  version: '0'
49
75
  requirements: []
50
76
  rubyforge_project:
51
- rubygems_version: 1.8.23
77
+ rubygems_version: 1.8.25
52
78
  signing_key:
53
79
  specification_version: 3
54
80
  summary: Utilities to manipulate graph files
@@ -58,5 +84,4 @@ test_files:
58
84
  - tests/tests.rb
59
85
  - tests/node_tests.rb
60
86
  - tests/gdf_tests.rb
61
- - tests/gexf_tests.rb
62
87
  - tests/json_tests.rb
metadata.gz.sig ADDED
Binary file
data/tests/gexf_tests.rb DELETED
@@ -1,4 +0,0 @@
1
- #! /usr/bin/ruby1.9.1
2
- # -*- coding: UTF-8 -*-
3
-
4
- # require 'graphs/gexf'