projects
/
graph.njae.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c73f167
)
Added hash parameter to graph initialization
author
Neil Smith
<neil.github@njae.me.uk>
Fri, 10 Feb 2012 16:05:21 +0000
(16:05 +0000)
committer
Neil Smith
<neil.github@njae.me.uk>
Fri, 10 Feb 2012 16:05:21 +0000
(16:05 +0000)
Gemfile
patch
|
blob
|
history
Gemfile.lock
patch
|
blob
|
history
lib/graph.njae/edge.rb
patch
|
blob
|
history
lib/graph.njae/graph.rb
patch
|
blob
|
history
lib/graph.njae/vertex.rb
patch
|
blob
|
history
spec/graph/edge_spec.rb
patch
|
blob
|
history
spec/graph/graph_spec.rb
patch
|
blob
|
history
spec/graph/vertex_spec.rb
patch
|
blob
|
history
diff --git
a/Gemfile
b/Gemfile
index d6b498fb33e8fc5f7a6d1556d256581d62551779..f677f3d2db9e7086230d0faa88ab187cbba78e09 100644
(file)
--- a/
Gemfile
+++ b/
Gemfile
@@
-6,9
+6,8
@@
source "http://rubygems.org"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
- gem "rspec", "~> 2.6.0"
- gem "bundler", "~> 1.0.0"
- gem "jeweler", "~> 1.6.2"
- gem "rcov", ">= 0"
+ gem "rspec"
+ gem "bundler"
+ gem "jeweler"
gem "rdoc"
end
gem "rdoc"
end
diff --git
a/Gemfile.lock
b/Gemfile.lock
index 024a43aff37e114ec4542cae7494b01eb7830a87..9b1b95bce3c4f321cef4e1b43dc973e6891a0f5c 100644
(file)
--- a/
Gemfile.lock
+++ b/
Gemfile.lock
@@
-1,30
+1,31
@@
GEM
remote: http://rubygems.org/
specs:
GEM
remote: http://rubygems.org/
specs:
- diff-lcs (1.1.
2
)
+ diff-lcs (1.1.
3
)
git (1.2.5)
git (1.2.5)
- jeweler (1.
6.2
)
+ jeweler (1.
8.3
)
bundler (~> 1.0)
git (>= 1.2.5)
rake
bundler (~> 1.0)
git (>= 1.2.5)
rake
- rake (0.9.2)
- rcov (0.9.9)
- rdoc (3.7)
- rspec (2.6.0)
- rspec-core (~> 2.6.0)
- rspec-expectations (~> 2.6.0)
- rspec-mocks (~> 2.6.0)
- rspec-core (2.6.4)
- rspec-expectations (2.6.0)
+ rdoc
+ json (1.6.5)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
diff-lcs (~> 1.1.2)
diff-lcs (~> 1.1.2)
- rspec-mocks (2.
6
.0)
+ rspec-mocks (2.
8
.0)
PLATFORMS
ruby
DEPENDENCIES
PLATFORMS
ruby
DEPENDENCIES
- bundler (~> 1.0.0)
- jeweler (~> 1.6.2)
- rcov
+ bundler
+ jeweler
rdoc
rdoc
- rspec
(~> 2.6.0)
+ rspec
diff --git
a/lib/graph.njae/edge.rb
b/lib/graph.njae/edge.rb
index f38a32b21e693bbf645c25bdcca159579f97dceb..814360ba818818cd43df1cf0859208d324098c20 100644
(file)
--- a/
lib/graph.njae/edge.rb
+++ b/
lib/graph.njae/edge.rb
@@
-10,8
+10,8
@@
module GraphNjae
# Each connection is handled by a Graph::Connection object, so that each end
# of the Edge can have it's own attributes.
class Edge < OpenStruct
# Each connection is handled by a Graph::Connection object, so that each end
# of the Edge can have it's own attributes.
class Edge < OpenStruct
- def initialize
- super
+ def initialize
(values = {})
+ super
(values)
self.connections = []
self
end
self.connections = []
self
end
diff --git
a/lib/graph.njae/graph.rb
b/lib/graph.njae/graph.rb
index e08a1ad8544d12aec4cacf3a095ca5e1e5df6aea..b1de59b324be4297ceed4ef6c1a8dd2fdfe890df 100644
(file)
--- a/
lib/graph.njae/graph.rb
+++ b/
lib/graph.njae/graph.rb
@@
-7,8
+7,8
@@
module GraphNjae
# A container for all the parts of a graph. The graph can have arbitrary attributes,
# treated as method names.
class Graph < OpenStruct
# A container for all the parts of a graph. The graph can have arbitrary attributes,
# treated as method names.
class Graph < OpenStruct
- def initialize
- super
+ def initialize
(values = {})
+ super
(values)
self.edges = Array.new
self.vertices = Array.new
self
self.edges = Array.new
self.vertices = Array.new
self
@@
-23,5
+23,20
@@
module GraphNjae
end
self
end
end
self
end
- end
+
+ # Form a product graph of this graph and the other.
+ # Return the new graph.
+ def product(other)
+ product_graph = Graph.new
+ self.vertices.each do |v1|
+ other.vertices.each do |v2|
+ product_vertex = Vertex.new
+ product_vertex.left_node = v1
+ product_vertex.right_node = v2
+ product_graph << product_vertex
+ end
+ end
+ end
+
+ end # class
end
end
diff --git
a/lib/graph.njae/vertex.rb
b/lib/graph.njae/vertex.rb
index 4a75b6df2c628c0cba8a25fead7aff670a1c1563..6b34351740c04c0754a5e431f1ea38bd7773a0a0 100644
(file)
--- a/
lib/graph.njae/vertex.rb
+++ b/
lib/graph.njae/vertex.rb
@@
-6,8
+6,8
@@
module GraphNjae
# A vertex in a graph. The edge can have arbitrary attributes,treated as
# method names.
class Vertex < OpenStruct
# A vertex in a graph. The edge can have arbitrary attributes,treated as
# method names.
class Vertex < OpenStruct
- def initialize
- super
+ def initialize
(values = {})
+ super
(values)
self.edges = []
self
end
self.edges = []
self
end
diff --git
a/spec/graph/edge_spec.rb
b/spec/graph/edge_spec.rb
index 2e7dbfcc9a64863648ed928699155ea173c004b0..d139667126886b8c382368378ab1c43aafe44fc5 100644
(file)
--- a/
spec/graph/edge_spec.rb
+++ b/
spec/graph/edge_spec.rb
@@
-8,6
+8,15
@@
module GraphNjae
e = Edge.new
e.connections.should be_empty
end
e = Edge.new
e.connections.should be_empty
end
+
+ it "creates an edge with some parameters" do
+ e = Edge.new :value1 => 1, :value2 => "value2", :value3 => :v3
+ e.value1.should == 1
+ e.value2.should == "value2"
+ e.value3.should == :v3
+ e.value4.should be_nil
+ end
+
end # #initialize
describe "adds attribues" do
end # #initialize
describe "adds attribues" do
diff --git
a/spec/graph/graph_spec.rb
b/spec/graph/graph_spec.rb
index 09cc6a433cddd36d28d78fa4c09fc9f2542450da..5da61f5ef1b2bd627e0d285bb873401c6ea28c17 100644
(file)
--- a/
spec/graph/graph_spec.rb
+++ b/
spec/graph/graph_spec.rb
@@
-16,6
+16,15
@@
module GraphNjae
g.edges.should be_empty
g.vertices.should be_empty
end
g.edges.should be_empty
g.vertices.should be_empty
end
+
+ it "creates a graph with some parameters" do
+ g = Graph.new :value1 => 1, :value2 => "value2", :value3 => :v3
+ g.value1.should == 1
+ g.value2.should == "value2"
+ g.value3.should == :v3
+ g.value4.should be_nil
+ end
+
end # #initialize
describe "adds attribues" do
end # #initialize
describe "adds attribues" do
diff --git
a/spec/graph/vertex_spec.rb
b/spec/graph/vertex_spec.rb
index 49ce58ccf92b6c234b9ce2a4264b4e6f4ece74c0..b193bc81057558d24f9cf10ca7674937cb5d570d 100644
(file)
--- a/
spec/graph/vertex_spec.rb
+++ b/
spec/graph/vertex_spec.rb
@@
-9,6
+9,14
@@
module GraphNjae
v = Vertex.new
v.edges.should be_empty
end
v = Vertex.new
v.edges.should be_empty
end
+
+ it "creates a vertex with some parameters" do
+ v = Vertex.new :value1 => 1, :value2 => "value2", :value3 => :v3
+ v.value1.should == 1
+ v.value2.should == "value2"
+ v.value3.should == :v3
+ v.value4.should be_nil
+ end
end # #initialize
describe "adds attribues" do
end # #initialize
describe "adds attribues" do