5 # Needed as RSpec includes the Psych YAML reader, which defines :y as
6 # a method for generating YAML of an object.
11 describe
"#contains?" do
12 it
"reports when a box contains another" do
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
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
)
25 describe
"#within?" do
26 it
"reports when a box is within another" do
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
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
41 describe
"#similarity" do
42 it
"find the similarity of two boxes" do
44 b1
.name
= Label
.new
"box 1", true
46 b2
.name
= Label
.new
"box 2", true
47 b1
.similarity(b2
).should
be_within(0.005).of(0.75)