# 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
remote: http://rubygems.org/
specs:
- diff-lcs (1.1.2)
+ diff-lcs (1.1.3)
git (1.2.5)
- jeweler (1.6.2)
+ jeweler (1.8.3)
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)
- rspec-mocks (2.6.0)
+ rspec-mocks (2.8.0)
PLATFORMS
ruby
DEPENDENCIES
- bundler (~> 1.0.0)
- jeweler (~> 1.6.2)
- rcov
+ bundler
+ jeweler
rdoc
- rspec (~> 2.6.0)
+ rspec
# 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
# 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
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
# 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
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
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
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