X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=spec%2Ferd_handler%2Ferd_spec.rb;h=77d7ad2b42dbf19531a3684ea4a41cb23fbbcb31;hb=f55cef415b384cf2004cf984cb0aaf6bd87ee922;hp=d6d5561e4cb34274d26b0e0fa4fda870ed2b3751;hpb=042a27abb3ac3bf9faf36406204fe1d1901123d3;p=erd-marker.git diff --git a/spec/erd_handler/erd_spec.rb b/spec/erd_handler/erd_spec.rb index d6d5561..77d7ad2 100644 --- a/spec/erd_handler/erd_spec.rb +++ b/spec/erd_handler/erd_spec.rb @@ -71,6 +71,20 @@ module ErdHandler c1.should_not == c2 end + it "reads and creates an ERD with subclassing" do + erd = Erd.new + erd.read(File.new("spec/fixtures/two_boxes_one_contained_erd.xml")) + erd.mark.should == 4.5 + erd.should have(2).vertices + erd.should have(0).edges + + erd.vertices[0].should have(0).neighbours + erd.vertices[1].should have(0).neighbours + + erd.vertices[0].within?(erd.vertices[1]).should be(true) + erd.vertices[1].should be_contains(erd.vertices[0]) + end + it "reads and creates full diagram" do erd = Erd.new erd.read(File.new("spec/fixtures/complex_erd.xml")) @@ -141,5 +155,62 @@ module ErdHandler l5.connections.find {|c| c.crowsfoot == :no}.end.should be b2 end end # #read + + describe "#mmus" do + it "finds three MMUs in a simple ERD" do + erd = Erd.new + erd.read(File.new("spec/fixtures/two_boxes_one_link_erd.xml")) + mmus = erd.mmus + + mmus.should have(3).items + single_box_mmus = mmus.select {|m| m.vertices.length == 1} + single_link_mmus = mmus.select {|m| m.edges.length == 1} + + single_box_mmus.should have(2).items + single_box_mmus.each do |m| + m.should have(1).vertices + m.should have(0).edges + end + + single_link_mmus.should have(1).items + single_link_mmus.each do |m| + m.should have(2).vertices + m.should have(1).edges + m.edges.first.should have(2).connections + m.vertices.each do |v| + m.vertices.should include(v) + end + end + end + + it "finds many MMUs in a complex ERD" do + erd = Erd.new + erd.read(File.new("spec/fixtures/complex_erd.xml")) + mmus = erd.mmus + + mmus.should have(11).items + single_box_mmus = mmus.select {|m| m.vertices.length == 1} + single_link_mmus = mmus.select {|m| m.edges.length == 1} + + single_box_mmus.should have(5).items + single_box_mmus.each do |m| + m.should have(1).vertices + m.should have(0).edges + end + single_box_mmus.map {|m| m.vertices.first.name.original}.uniq.should have(5).items + + single_link_mmus.should have(6).items + single_link_mmus.each do |m| + m.should have(2).vertices + m.should have(1).edges + m.edges.first.should have(2).connections + m.vertices.each do |v| + m.vertices.should include(v) + end + end + single_link_mmus.map {|m| m.edges.first.name.original}.uniq.should have(6).items + end + + end # #mmus end end