Added simplecov
[erd-marker.git] / spec / erd_handler / box_spec.rb
1 require 'spec_helper'
2
3 module ErdHandler
4 describe Box do
5 # Needed as RSpec includes the Psych YAML reader, which defines :y as
6 # a method for generating YAML of an object.
7 class Box
8 undef_method :y
9 end
10
11 describe "#contains?" do
12 it "reports when a box contains another" do
13 b1 = Box.new
14 b1.x = 10 ; b1.y = 10 ; b1.width = 20 ; b1.height = 20
15 b2 = Box.new ; b2.x = 5 ; b2.y = 5 ; b2.width = 30 ; b2.height = 30
16 b3 = Box.new ; b3.x = 15 ; b3.y = 15 ; b3.width = 20 ; b3.height = 20
17
18 b1.should_not be_contains(b2)
19 b2.should be_contains(b1)
20 b1.should_not be_contains(b3)
21 b3.should_not be_contains(b1)
22 end
23 end # contains?
24
25 describe "#within?" do
26 it "reports when a box is within another" do
27 b1 = Box.new
28 b1.x = 10 ; b1.y = 10 ; b1.width = 20 ; b1.height = 20
29 b2 = Box.new ; b2.x = 5 ; b2.y = 5 ; b2.width = 30 ; b2.height = 30
30 b3 = Box.new ; b3.x = 15 ; b3.y = 15 ; b3.width = 20 ; b3.height = 20
31
32 # Can't use the standard RSpec predicate notation as it clashes with
33 # floating-point expectations
34 b1.within?(b2).should == true
35 b2.within?(b1).should == false
36 b1.within?(b3).should == false
37 b3.within?(b1).should == false
38 end
39 end # within?
40
41 describe "#similarity" do
42 it "find the similarity of two boxes" do
43 b1 = Box.new
44 b1.name = Label.new "box 1", true
45 b2 = Box.new
46 b2.name = Label.new "box 2", true
47 b1.similarity(b2).should be_within(0.005).of(0.75)
48 end
49 end
50
51 end
52 end