From 17ad3d5f9603f86a41b677a3a064fc7bc503d659 Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 6 Jul 2012 08:00:05 +0100 Subject: [PATCH] End of day --- lib/erd_handler.rb | 14 +- lib/erd_handler/abstract_erd.rb | 21 ++- lib/erd_handler/box.rb | 16 +-- lib/erd_handler/erd.rb | 9 +- lib/erd_handler/link.rb | 4 +- spec/erd_handler/abstract_erd_spec.rb | 22 +-- spec/erd_handler/box_spec.rb | 16 +-- spec/erd_handler/erd_spec.rb | 65 +++++---- spec/erd_handler/label_spec.rb | 188 +++++++++++++------------- spec/spec_helper.rb | 6 - 10 files changed, 183 insertions(+), 178 deletions(-) diff --git a/lib/erd_handler.rb b/lib/erd_handler.rb index bea10a1..a77d287 100644 --- a/lib/erd_handler.rb +++ b/lib/erd_handler.rb @@ -1,16 +1,18 @@ require 'bundler/setup' require 'rexml/document' -include REXML require 'graph.njae' include GraphNjae require 'porter2stemmer' +require 'logger' -require 'erd_handler/label' -require 'erd_handler/erd' -require 'erd_handler/box' -require 'erd_handler/link' -require 'erd_handler/abstract_erd' +require_relative 'erd_handler/exceptions' +require_relative 'erd_handler/logger' +require_relative 'erd_handler/label' +require_relative 'erd_handler/erd' +require_relative 'erd_handler/box' +require_relative 'erd_handler/link' +require_relative 'erd_handler/abstract_erd' diff --git a/lib/erd_handler/abstract_erd.rb b/lib/erd_handler/abstract_erd.rb index c5e2a3a..c3e8a77 100644 --- a/lib/erd_handler/abstract_erd.rb +++ b/lib/erd_handler/abstract_erd.rb @@ -17,9 +17,12 @@ module ErdHandler end erd.edges.each do |e| link_vertex = AbstractEdge.new(e) + self << link_vertex e.connections.each do |c| - # find the abstract vertex at this end - # connect the abstract link to it + connection = AbstractConnection.new(c) + self << connection + self << link_vertex.connect(connection) + self << connection.connect(self.vertices.find {|v| v.base_vertex == c.end}) end end self @@ -27,9 +30,9 @@ module ErdHandler end class AbstractBox < Vertex - def initialize(souce = nil) + def initialize(source) super() - self.base_vertex = source unless source.nil? + self.base_vertex = source self end end @@ -37,7 +40,15 @@ module ErdHandler class AbstractEdge < Vertex def initialize(source = nil) super() - self.base_vertex = source unless source.nil? + self.base_edge = source unless source.nil? + self + end + end + + class AbstractConnection < Vertex + def initialize(source = nil) + super() + self.base_connection = source unless source.nil? self end end diff --git a/lib/erd_handler/box.rb b/lib/erd_handler/box.rb index 244b411..edd05dc 100644 --- a/lib/erd_handler/box.rb +++ b/lib/erd_handler/box.rb @@ -7,15 +7,15 @@ module ErdHandler end # initialize def read(box_element) - self.id = box_element.attributes["id"].to_i - self.name = Label.new box_element.attributes["name"] - self.mark = box_element.attributes["mark"].to_f + self.id = box_element.attributes['id'].to_i + self.name = Label.new box_element.attributes['name'] + self.mark = box_element.attributes['mark'].to_f - self.x = box_element.elements["location"].attributes["x"].to_f - self.y = box_element.elements["location"].attributes["y"].to_f - self.width = box_element.elements["size"].attributes["width"].to_f - self.height = box_element.elements["size"].attributes["height"].to_f - self.comment = box_element.elements["comment"].text + self.x = box_element.elements['location'].attributes['x'].to_f + self.y = box_element.elements['location'].attributes['y'].to_f + self.width = box_element.elements['size'].attributes['width'].to_f + self.height = box_element.elements['size'].attributes['height'].to_f + self.comment = box_element.elements['comment'].text self end diff --git a/lib/erd_handler/erd.rb b/lib/erd_handler/erd.rb index 2c10364..09f3661 100644 --- a/lib/erd_handler/erd.rb +++ b/lib/erd_handler/erd.rb @@ -7,10 +7,11 @@ module ErdHandler end def read(source) - doc = Document.new(source) - raise InvalidErdFile unless doc.elements.to_a.length == 1 and doc.elements[1].name.downcase == 'drawing' - self.mark = doc.elements['Drawing'].attributes["mark"].to_f - self.name = Label.new doc.elements['Drawing'].attributes["name"] + doc = REXML::Document.new(source) + raise(InvalidErdFile, "#{source} doesn't contain a drawing element") unless doc.elements[1].name.downcase == 'drawing' + raise(InvalidErdFile, "#{source} doesn't have one drawing element") unless doc.elements.to_a.length == 1 + self.mark = doc.elements['Drawing'].attributes['mark'].to_f + self.name = Label.new doc.elements['Drawing'].attributes['name'] doc.elements.each('Drawing/box') do |box_element| self << Box.new(box_element) end diff --git a/lib/erd_handler/link.rb b/lib/erd_handler/link.rb index 63bfd06..3b7ff59 100644 --- a/lib/erd_handler/link.rb +++ b/lib/erd_handler/link.rb @@ -7,8 +7,8 @@ module ErdHandler end def read(link_element, vertices) - self.id = link_element.attributes["id"].to_i - self.mark = link_element.attributes["mark"].to_f + self.id = link_element.attributes['id'].to_i + self.mark = link_element.attributes['mark'].to_f self.name = Label.new link_element.elements['moveableName'].attributes['name'] 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] diff --git a/spec/erd_handler/abstract_erd_spec.rb b/spec/erd_handler/abstract_erd_spec.rb index 67fe7c7..361bfe1 100644 --- a/spec/erd_handler/abstract_erd_spec.rb +++ b/spec/erd_handler/abstract_erd_spec.rb @@ -2,15 +2,15 @@ require 'spec_helper' module ErdHandler describe AbstractErd do - describe "#initialize" do - it "creates an empty abstract ERD" do + describe '#initialize' do + it 'creates an empty abstract ERD' do aerd = AbstractErd.new aerd.should have(0).vertices aerd.should have(0).edges end - it "reads and creates a single box" do - erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml")) + it 'reads and creates a single box' do + erd = Erd.new(File.new('spec/fixtures/single_box_erd.xml')) aerd = AbstractErd.new(erd) aerd.mark.should == 6.5 aerd.should have(1).vertices @@ -18,9 +18,9 @@ module ErdHandler end end # #initialize - describe "#abstract" do - it "reads and creates a single box" do - erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml")) + describe '#abstract' do + it 'creates abstract graph of a single box' do + erd = Erd.new(File.new('spec/fixtures/single_box_erd.xml')) aerd = AbstractErd.new aerd.abstract erd aerd.mark.should == 6.5 @@ -28,13 +28,13 @@ module ErdHandler aerd.should have(0).edges end - it "reads and creates two boxes with an edge joining them" do - erd = Erd.new(File.new("spec/fixtures/two_boxes_one_link_erd.xml")) + it 'creates abstract graph of two boxes with an edge joining them' do + erd = Erd.new(File.new('spec/fixtures/two_boxes_one_link_erd.xml')) aerd = AbstractErd.new aerd.abstract erd aerd.mark.should == 4.5 - aerd.should have(3).vertices - aerd.should have(2).edges + aerd.should have(5).vertices + aerd.should have(4).edges end end # #abstract diff --git a/spec/erd_handler/box_spec.rb b/spec/erd_handler/box_spec.rb index 1d47ed7..98294c4 100644 --- a/spec/erd_handler/box_spec.rb +++ b/spec/erd_handler/box_spec.rb @@ -8,8 +8,8 @@ module ErdHandler undef_method :y end - describe "#contains?" do - it "reports when a box contains another" do + describe '#contains?' do + it 'reports when a box contains another' do b1 = Box.new b1.x = 10 ; b1.y = 10 ; b1.width = 20 ; b1.height = 20 b2 = Box.new ; b2.x = 5 ; b2.y = 5 ; b2.width = 30 ; b2.height = 30 @@ -22,8 +22,8 @@ module ErdHandler end end # contains? - describe "#within?" do - it "reports when a box is within another" do + describe '#within?' do + it 'reports when a box is within another' do b1 = Box.new b1.x = 10 ; b1.y = 10 ; b1.width = 20 ; b1.height = 20 b2 = Box.new ; b2.x = 5 ; b2.y = 5 ; b2.width = 30 ; b2.height = 30 @@ -38,12 +38,12 @@ module ErdHandler end end # within? - describe "#similarity" do - it "find the similarity of two boxes" do + describe '#similarity' do + it 'find the similarity of two boxes' do b1 = Box.new - b1.name = Label.new "box 1", true + b1.name = Label.new 'box 1', true b2 = Box.new - b2.name = Label.new "box 2", true + b2.name = Label.new 'box 2', true b1.similarity(b2).should be_within(0.005).of(0.75) end end diff --git a/spec/erd_handler/erd_spec.rb b/spec/erd_handler/erd_spec.rb index c9ec5b0..aff330a 100644 --- a/spec/erd_handler/erd_spec.rb +++ b/spec/erd_handler/erd_spec.rb @@ -2,38 +2,35 @@ require 'spec_helper' module ErdHandler describe Erd do - let(:input) { double('input').as_null_object } - let(:output) { double('output').as_null_object } - let(:erd) { Erd.new(input) } - describe "#initialize" do - it "creates an empty ERD" do + describe '#initialize' do + it 'creates an empty ERD' do erd = Erd.new erd.mark.should be_nil erd.should have(0).vertices erd.should have(0).edges end - it "reads and creates a single box" do - erd = Erd.new(File.new("spec/fixtures/single_box_erd.xml")) + it 'reads and creates a single box' do + erd = Erd.new(File.new('spec/fixtures/single_box_erd.xml')) erd.mark.should == 6.5 erd.should have(1).vertices erd.should have(0).edges end end # #initialize - describe "#read" do - it "reads and creates a single box" do + describe '#read' do + it 'reads and creates a single box' do erd = Erd.new - erd.read(File.new("spec/fixtures/single_box_erd.xml")) + erd.read(File.new('spec/fixtures/single_box_erd.xml')) erd.mark.should == 6.5 erd.should have(1).vertices erd.should have(0).edges end - it "reads and creates two boxes with an edge joining them" do + it 'reads and creates two boxes with an edge joining them' do erd = Erd.new - erd.read(File.new("spec/fixtures/two_boxes_one_link_erd.xml")) + erd.read(File.new('spec/fixtures/two_boxes_one_link_erd.xml')) erd.mark.should == 4.5 erd.should have(2).vertices erd.should have(1).edges @@ -52,9 +49,9 @@ module ErdHandler link.connection_at(b1).crowsfoot.should be(:no) end - it "reads and creates a box with a self-loop" do + it 'reads and creates a box with a self-loop' do erd = Erd.new - erd.read(File.new("spec/fixtures/single_box_self_loop_erd.xml")) + erd.read(File.new('spec/fixtures/single_box_self_loop_erd.xml')) erd.mark.should == 4.5 erd.should have(1).vertices erd.should have(1).edges @@ -71,9 +68,9 @@ module ErdHandler c1.should_not == c2 end - it "reads and creates an ERD with subclassing" do + 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.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 @@ -85,70 +82,70 @@ module ErdHandler erd.vertices[1].should be_contains(erd.vertices[0]) end - it "reads and creates full diagram" do + it 'reads and creates full diagram' do erd = Erd.new - erd.read(File.new("spec/fixtures/complex_erd.xml")) + erd.read(File.new('spec/fixtures/complex_erd.xml')) erd.mark.should == 4.0 erd.should have(5).vertices erd.should have(6).edges b0 = erd.vertices.find {|b| b.id == 0} - b0.name.original.should == "Unit" + b0.name.original.should == 'Unit' b0.should have(2).neighbours b1 = erd.vertices.find {|b| b.id == 1} - b1.name.original.should == "Employee" + b1.name.original.should == 'Employee' b1.should have(2).neighbours b2 = erd.vertices.find {|b| b.id == 2} - b2.name.original.should == "Course" + b2.name.original.should == 'Course' b2.should have(3).neighbours b3 = erd.vertices.find {|b| b.id == 3} - b3.name.original.should == "Presentation" + b3.name.original.should == 'Presentation' b3.should have(3).neighbours b4 = erd.vertices.find {|b| b.id == 4} - b4.name.original.should == "Client" + b4.name.original.should == 'Client' b4.should have(1).neighbours l0 = erd.edges.find {|e| e.id == 0} - l0.name.original.should == "ConsistsOf" + l0.name.original.should == 'ConsistsOf' l0.connections.find {|c| c.end == b0}.blob.should be :closed l0.connections.find {|c| c.end == b0}.crowsfoot.should be :yes l0.connections.find {|c| c.end == b2}.blob.should be :closed l0.connections.find {|c| c.end == b2}.crowsfoot.should be :no l1 = erd.edges.find {|e| e.id == 1} - l1.name.original.should == "Prepares" + l1.name.original.should == 'Prepares' l1.connections.find {|c| c.end == b0}.blob.should be :open l1.connections.find {|c| c.end == b0}.crowsfoot.should be :yes l1.connections.find {|c| c.end == b1}.blob.should be :closed l1.connections.find {|c| c.end == b1}.crowsfoot.should be :no l2 = erd.edges.find {|e| e.id == 2} - l2.name.original.should == "Presents" + l2.name.original.should == 'Presents' l2.connections.find {|c| c.end == b1}.blob.should be :closed l2.connections.find {|c| c.end == b1}.crowsfoot.should be :no l2.connections.find {|c| c.end == b3}.blob.should be :closed l2.connections.find {|c| c.end == b3}.crowsfoot.should be :yes l3 = erd.edges.find {|e| e.id == 3} - l3.name.original.should == "Presented" + l3.name.original.should == 'Presented' l3.connections.find {|c| c.end == b2}.blob.should be :open l3.connections.find {|c| c.end == b2}.crowsfoot.should be :no l3.connections.find {|c| c.end == b3}.blob.should be :closed l3.connections.find {|c| c.end == b3}.crowsfoot.should be :yes l4 = erd.edges.find {|e| e.id == 4} - l4.name.original.should == "Recieves" + l4.name.original.should == 'Recieves' l4.connections.find {|c| c.end == b3}.blob.should be :closed l4.connections.find {|c| c.end == b3}.crowsfoot.should be :yes l4.connections.find {|c| c.end == b4}.blob.should be :closed l4.connections.find {|c| c.end == b4}.crowsfoot.should be :no l5 = erd.edges.find {|e| e.id == 5} - l5.name.original.should == "IsPrerequisiteOf" + l5.name.original.should == 'IsPrerequisiteOf' l5.connections.find {|c| c.crowsfoot == :yes}.blob.should be :open l5.connections.find {|c| c.crowsfoot == :no}.blob.should be :open l5.connections.find {|c| c.crowsfoot == :yes}.end.should be b2 @@ -156,10 +153,10 @@ module ErdHandler end end # #read - describe "#mmus" do - it "finds three MMUs in a simple ERD" do + 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")) + erd.read(File.new('spec/fixtures/two_boxes_one_link_erd.xml')) mmus = erd.mmus mmus.should have(3).items @@ -183,9 +180,9 @@ module ErdHandler end end - it "finds many MMUs in a complex ERD" do + it 'finds many MMUs in a complex ERD' do erd = Erd.new - erd.read(File.new("spec/fixtures/complex_erd.xml")) + erd.read(File.new('spec/fixtures/complex_erd.xml')) mmus = erd.mmus mmus.should have(11).items diff --git a/spec/erd_handler/label_spec.rb b/spec/erd_handler/label_spec.rb index 6f09b95..e2364a0 100644 --- a/spec/erd_handler/label_spec.rb +++ b/spec/erd_handler/label_spec.rb @@ -3,19 +3,19 @@ require 'spec_helper' module ErdHandler describe Label do describe '#initialize' do - it "should give an error if not given an original string" do + it 'should give an error if not given an original string' do # Label.new.should raise_error(ArgumentError) expect {Label.new}.to raise_error(ArgumentError) end - it "should create a copy of the original as the processed string" do - test_label = "Test label" + it 'should create a copy of the original as the processed string' do + test_label = 'Test label' l1 = Label.new test_label l1.original.should == test_label end - it "should tidy the processed string if asked" do - test_label = "testingLabeller string, he_pontificated" + it 'should tidy the processed string if asked' do + test_label = 'testingLabeller string, he_pontificated' l1 = Label.new test_label.dup, true l2 = Label.new test_label.dup l2.split.downcase.stem @@ -24,18 +24,18 @@ module ErdHandler end # initialze describe '#original' do - it "reports the string it was initialised with" do - test_label = "Test label" + it 'reports the string it was initialised with' do + test_label = 'Test label' l1 = Label.new test_label l1.original.should == test_label #l1 = Label.new - #l1.original.should == "" + #l1.original.should == '' end end # original describe '#processed' do - it "reports the original if no processing has been done" do - test_label = "Test label" + it 'reports the original if no processing has been done' do + test_label = 'Test label' l1 = Label.new test_label l1.processed.should == [test_label] l1.original.should == test_label @@ -43,124 +43,124 @@ module ErdHandler end # processed describe '#split' do - it "splits the original on the specified regexp" do - l1 = Label.new "Test label" + it 'splits the original on the specified regexp' do + l1 = Label.new 'Test label' l1.split(/ /) - l1.processed.should == ["Test", "label"] - l1.original.should == "Test label" + l1.processed.should == ['Test', 'label'] + l1.original.should == 'Test label' - l1 = Label.new "Test_label" + l1 = Label.new 'Test_label' l1.split(/_/) - l1.processed.should == ["Test", "label"] + l1.processed.should == ['Test', 'label'] - l1 = Label.new "Test label_string" + l1 = Label.new 'Test label_string' l1.split(/[ _]/) - l1.processed.should == ["Test", "label", "string"] + l1.processed.should == ['Test', 'label', 'string'] end - it "splits the original on camel case" do - l1 = Label.new "TestLabel" + it 'splits the original on camel case' do + l1 = Label.new 'TestLabel' l1.split :camel_case => true - l1.processed.should == ["Test", "Label"] - l1.original.should == "TestLabel" + l1.processed.should == ['Test', 'Label'] + l1.original.should == 'TestLabel' - l2 = Label.new "testLabel" + l2 = Label.new 'testLabel' l2.split :camel_case => true - l2.processed.should == ["test", "Label"] - l2.original.should == "testLabel" + l2.processed.should == ['test', 'Label'] + l2.original.should == 'testLabel' end - it "doesn't split the original on camel case if asked not to" do - l1 = Label.new "TestLabel" + it 'does not split the original on camel case if asked not to' do + l1 = Label.new 'TestLabel' l1.split :camel_case => false - l1.processed.should == ["TestLabel"] - l1.original.should == "TestLabel" + l1.processed.should == ['TestLabel'] + l1.original.should == 'TestLabel' - l2 = Label.new "TestLabel" + l2 = Label.new 'TestLabel' l2.split :camel_case => nil - l2.processed.should == ["TestLabel"] - l2.original.should == "TestLabel" + l2.processed.should == ['TestLabel'] + l2.original.should == 'TestLabel' end - it "splits the original on numbers" do - l1 = Label.new "Test123Label" + it 'splits the original on numbers' do + l1 = Label.new 'Test123Label' l1.split :numbers => true - l1.processed.should == ["Test", "123", "Label"] - l1.original.should == "Test123Label" + l1.processed.should == ['Test', '123', 'Label'] + l1.original.should == 'Test123Label' - l2 = Label.new "test1label" + l2 = Label.new 'test1label' l2.split :numbers => true - l2.processed.should == ["test", "1", "label"] - l2.original.should == "test1label" + l2.processed.should == ['test', '1', 'label'] + l2.original.should == 'test1label' end - it "doesn't split the original on numbers if asked not to" do - l1 = Label.new "Test123Label" + it 'does not split the original on numbers if asked not to' do + l1 = Label.new 'Test123Label' l1.split :numbers => false - l1.processed.should == ["Test123Label"] - l1.original.should == "Test123Label" + l1.processed.should == ['Test123Label'] + l1.original.should == 'Test123Label' - l2 = Label.new "Test123Label" + l2 = Label.new 'Test123Label' l2.split :numbers => nil - l2.processed.should == ["Test123Label"] - l2.original.should == "Test123Label" + l2.processed.should == ['Test123Label'] + l2.original.should == 'Test123Label' end - it "splits the original using a default regexp" do + it 'splits the original using a default regexp' do l1 = Label.new "Test label_string\tfred" l1.split - l1.processed.should == ["Test", "label", "string", "fred"] + l1.processed.should == ['Test', 'label', 'string', 'fred'] end - it "splits the original on camel case by default" do - l1 = Label.new "TestLabel" + it 'splits the original on camel case by default' do + l1 = Label.new 'TestLabel' l1.split - l1.processed.should == ["Test", "Label"] - l1.original.should == "TestLabel" + l1.processed.should == ['Test', 'Label'] + l1.original.should == 'TestLabel' end - it "splits the original on numbers by default" do - l1 = Label.new "Test123Label" + it 'splits the original on numbers by default' do + l1 = Label.new 'Test123Label' l1.split - l1.processed.should == ["Test", "123", "Label"] - l1.original.should == "Test123Label" + l1.processed.should == ['Test', '123', 'Label'] + l1.original.should == 'Test123Label' end - it "splits the original on punctuation, whitespace, camel case, and numbers by default" do - l1 = Label.new "TestLabel is_split, 123 he,said456Fred" + it 'splits the original on punctuation, whitespace, camel case, and numbers by default' do + l1 = Label.new 'TestLabel is_split, 123 he,said456Fred' l1.split - l1.processed.should == ["Test", "Label", "is", "split","123", "he", "said", "456", "Fred"] - l1.original.should == "TestLabel is_split, 123 he,said456Fred" + l1.processed.should == ['Test', 'Label', 'is', 'split','123', 'he', 'said', '456', 'Fred'] + l1.original.should == 'TestLabel is_split, 123 he,said456Fred' end - it "is idempotent" do - l1 = Label.new "TestLabel is_split, 123 he,said456Fred" + it 'is idempotent' do + l1 = Label.new 'TestLabel is_split, 123 he,said456Fred' res1 = l1.split.dup res2 = l1.split res1.processed.should == res2.processed - l1.original.should == "TestLabel is_split, 123 he,said456Fred" + l1.original.should == 'TestLabel is_split, 123 he,said456Fred' end end # split - describe "#downcase" do - it "downcases all parts of the processed label" do - l1 = Label.new "Test label_string" + describe '#downcase' do + it 'downcases all parts of the processed label' do + l1 = Label.new 'Test label_string' l1.split.downcase - l1.processed.should == ["test", "label", "string"] + l1.processed.should == ['test', 'label', 'string'] end end # downcase - describe "#stem" do - it "stems all parts of the processed label" do - l1 = Label.new "testing labeller string pontificated" + describe '#stem' do + it 'stems all parts of the processed label' do + l1 = Label.new 'testing labeller string pontificated' l1.split.stem - l1.processed.should == ["test", "label", "string", "pontif"] + l1.processed.should == ['test', 'label', 'string', 'pontif'] end end # stem - describe "#tidy" do - it "tidies a label" do - l1 = Label.new "testingLabeller string, he_pontificated" + describe '#tidy' do + it 'tidies a label' do + l1 = Label.new 'testingLabeller string, he_pontificated' l2 = Label.new l1.original l1.tidy l2.split.downcase.stem @@ -168,33 +168,33 @@ module ErdHandler end end # tidy - describe "#length" do - it "returns the length of the processed label" do - l1 = Label.new "testingLabeller string, he_pontificated" + describe '#length' do + it 'returns the length of the processed label' do + l1 = Label.new 'testingLabeller string, he_pontificated' l1.tidy l1.length.should == l1.processed.join('').length end end # length - describe "#levenshtein" do - it "calculates the Levenshtein distance of the processed string" do - l1 = Label.new "Fred" - l1.levenshtein("Fred").should == 0 - l1.levenshtein("Free").should == 1 - l1.levenshtein("").should == 4 - l2 = Label.new "" - l2.levenshtein("Free").should == 4 - l2.levenshtein("").should == 0 - l3 = Label.new "meilenstein" - l3.levenshtein("levenshtein").should == 4 - l4 = Label.new "testingLabeller string, he_pontificated" - l4.tidy.levenshtein("testlabelstringhepontif").should == 0 - l4.tidy.levenshtein("testlabelXstringhepontif").should == 1 + describe '#levenshtein' do + it 'calculates the Levenshtein distance of the processed string' do + l1 = Label.new 'Fred' + l1.levenshtein('Fred').should == 0 + l1.levenshtein('Free').should == 1 + l1.levenshtein('').should == 4 + l2 = Label.new '' + l2.levenshtein('Free').should == 4 + l2.levenshtein('').should == 0 + l3 = Label.new 'meilenstein' + l3.levenshtein('levenshtein').should == 4 + l4 = Label.new 'testingLabeller string, he_pontificated' + l4.tidy.levenshtein('testlabelstringhepontif').should == 0 + l4.tidy.levenshtein('testlabelXstringhepontif').should == 1 end - it "calculates the Levenshtein distance between Labels" do - l1 = Label.new "meilenstein" - l2 = Label.new "levenshtein" + it 'calculates the Levenshtein distance between Labels' do + l1 = Label.new 'meilenstein' + l2 = Label.new 'levenshtein' l1.levenshtein(l2).should == 4 end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e82322e..d10b8b1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1 @@ -require 'rexml/document.rb' -include REXML - -require 'graph.njae' -include GraphNjae - require 'erd_handler' -- 2.34.1