From: Neil Smith Date: Wed, 18 Jul 2012 13:17:37 +0000 (+0100) Subject: Extended test cases X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=ff59dfc2421c2a740c523e5e4783090b21ab138e;p=erd-marker.git Extended test cases --- diff --git a/Gemfile.lock b/Gemfile.lock index 0a4459e..def4edb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,22 +2,21 @@ GEM remote: http://rubygems.org/ specs: diff-lcs (1.1.3) - graph.njae (0.2.4) - json (1.6.5) + graph.njae (0.4.0) + json (1.7.3) multi_json (1.3.6) - porter2stemmer (1.0.0) porter2stemmer (1.0.1) 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.8.0) + rspec (2.11.0) + rspec-core (~> 2.11.0) + rspec-expectations (~> 2.11.0) + rspec-mocks (~> 2.11.0) + rspec-core (2.11.0) + rspec-expectations (2.11.1) + diff-lcs (~> 1.1.3) + rspec-mocks (2.11.1) simplecov (0.6.4) multi_json (~> 1.0) simplecov-html (~> 0.5.3) diff --git a/lib/erd_handler/abstract_erd.rb b/lib/erd_handler/abstract_erd.rb index c3e8a77..fbcd89f 100644 --- a/lib/erd_handler/abstract_erd.rb +++ b/lib/erd_handler/abstract_erd.rb @@ -7,7 +7,7 @@ module ErdHandler end # Create an abstract ERD from a base ERD. - # An abstract ERD has an additional node for each link + # An abstract ERD has an additional vertex for each link and each end of the link def abstract(erd) self.mark = erd.mark self.name = erd.name @@ -16,10 +16,10 @@ module ErdHandler # also do links for containment end erd.edges.each do |e| - link_vertex = AbstractEdge.new(e) + link_vertex = AbstractLink.new(e) self << link_vertex e.connections.each do |c| - connection = AbstractConnection.new(c) + connection = AbstractLinkEnd.new(c) self << connection self << link_vertex.connect(connection) self << connection.connect(self.vertices.find {|v| v.base_vertex == c.end}) @@ -30,25 +30,25 @@ module ErdHandler end class AbstractBox < Vertex - def initialize(source) + def initialize(source = nil) super() - self.base_vertex = source + self.base_vertex = source unless source.nil? self end end - class AbstractEdge < Vertex + class AbstractLink < Vertex def initialize(source = nil) super() - self.base_edge = source unless source.nil? + self.base_link = source unless source.nil? self end end - class AbstractConnection < Vertex + class AbstractLinkEnd < Vertex def initialize(source = nil) super() - self.base_connection = source unless source.nil? + self.base_link_end = source unless source.nil? self end end diff --git a/lib/erd_handler/link.rb b/lib/erd_handler/link.rb index 3b7ff59..a73449b 100644 --- a/lib/erd_handler/link.rb +++ b/lib/erd_handler/link.rb @@ -13,8 +13,6 @@ module ErdHandler box1 = vertices.select {|v| v.id == link_element.elements['box1'].attributes['id'].to_i}[0] box2 = vertices.select {|v| v.id == link_element.elements['box2'].attributes['id'].to_i}[0] self << box1 << box2 - box1.edges << self - box2.edges << self unless box1 == box2 if box1 == box2 c1 = self.connections[0] c2 = self.connections[1] diff --git a/spec/erd_handler/abstract_erd_spec.rb b/spec/erd_handler/abstract_erd_spec.rb index 361bfe1..0aa1ccc 100644 --- a/spec/erd_handler/abstract_erd_spec.rb +++ b/spec/erd_handler/abstract_erd_spec.rb @@ -35,6 +35,22 @@ module ErdHandler aerd.mark.should == 4.5 aerd.should have(5).vertices aerd.should have(4).edges + v0 = aerd.vertices.find {|v| v.class == AbstractBox and v.base_vertex.id == 0} + v1 = aerd.vertices.find {|v| v.class == AbstractBox and v.base_vertex.id == 1} + e = aerd.vertices.find {|v| v.class == AbstractLink} + c0 = aerd.vertices.find {|v| v.class == AbstractLinkEnd and v.neighbours.include? v0} + c1 = aerd.vertices.find {|v| v.class == AbstractLinkEnd and v.neighbours.include? v1} + v0.should have(1).neighbours + v1.should have(1).neighbours + e.should have(2).neighbours + c0.should have(2).neighbours + c1.should have(2).neighbours + e.neighbours.should include(c0) + e.neighbours.should include(c1) + c0.neighbours.should include(e) + c0.neighbours.should include(v0) + c1.neighbours.should include(e) + c1.neighbours.should include(v1) end end # #abstract