spec/cg_rect_spec.rb in geomotion-0.1 vs spec/cg_rect_spec.rb in geomotion-0.5
- old
+ new
@@ -22,43 +22,69 @@
describe ".empty" do
it "should work" do
CGRectIsEmpty(CGRect.empty).should == true
end
+
+ it "should not be mutable" do
+ f = CGRect.empty
+ f.width = 10
+ f.height = 10
+ f.x = 10
+ f.y = 10
+ CGRectIsEmpty(CGRect.empty).should == true
+ end
end
describe "#empty?" do
it "should work" do
- p "ZERO1 #{CGRectZero.inspect}"
CGRectZero.empty?.should == true
end
end
describe ".null" do
it "should work" do
CGRectIsNull(CGRect.null).should == true
end
+
+ it "should not be mutable" do
+ f = CGRect.null
+ f.width = 10
+ f.height = 10
+ f.x = 10
+ f.y = 10
+ CGRectIsNull(CGRect.null).should == true
+ end
end
describe "#null?" do
it "should work" do
CGRectNull.null?.should == true
+ CGRect.null.null?.should == true
end
end
# Currently does NOT work due to some strange RM bug?
-=begin
describe ".infinite" do
it "should work" do
- CGRectIsInfinite(CGRect.infinite).should == true
+ CGRect.infinite.infinite?.should == true
end
+
+ it "should not be mutable" do
+ f = CGRect.infinite
+ f.width = 10
+ f.height = 10
+ f.x = 10
+ f.y = 10
+ CGRect.infinite.infinite?.should == true
+ end
end
-=end
describe "#infinite?" do
it "should work" do
CGRect.infinite.infinite?.should == true
+ CGRectInfinite.infinite?.should == true
end
end
describe "#intersects?" do
it "should work" do
@@ -219,10 +245,38 @@
rect = CGRect.empty.down(20)
rect.origin.y.should == 20
end
end
+ describe "#wider" do
+ it "works" do
+ rect = CGRect.empty.wider(20)
+ rect.size.width.should == 20
+ end
+ end
+
+ describe "#thinner" do
+ it "works" do
+ rect = CGRect.empty.thinner(20)
+ rect.size.width.should == -20
+ end
+ end
+
+ describe "#taller" do
+ it "works" do
+ rect = CGRect.empty.taller(20)
+ rect.size.height.should == 20
+ end
+ end
+
+ describe "#shorter" do
+ it "works" do
+ rect = CGRect.empty.shorter(20)
+ rect.size.height.should == -20
+ end
+ end
+
describe "#above" do
it "works with margins" do
rect = CGRect.make(height: 50).above(20)
rect.origin.y.should == -70
end
@@ -264,10 +318,54 @@
rect = CGRect.make(x: 50, width: 20).beside
rect.origin.x.should == 70
end
end
+ describe "#beside:width:" do
+ it "works" do
+ rect = CGRect.make(x: 50, width: 20).beside(10, width: 30)
+ rect.origin.x.should == 80
+ rect.size.width.should == 30
+ end
+ end
+
+ describe "#top_left" do
+ it "works" do
+ rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
+ point = rect.top_left
+ point.is_a?(CGPoint).should == true
+ CGPointEqualToPoint(point, CGPointMake(10, 20)).should == true
+ end
+ end
+
+ describe "#bottom_left" do
+ it "works" do
+ rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
+ point = rect.bottom_left
+ point.is_a?(CGPoint).should == true
+ CGPointEqualToPoint(point, CGPointMake(10, 220)).should == true
+ end
+ end
+
+ describe "#top_right" do
+ it "works" do
+ rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
+ point = rect.top_right
+ point.is_a?(CGPoint).should == true
+ CGPointEqualToPoint(point, CGPointMake(110, 20)).should == true
+ end
+ end
+
+ describe "#bottom_right" do
+ it "works" do
+ rect = CGRect.make(x: 10, y: 20, width: 100, height: 200)
+ point = rect.bottom_right
+ point.is_a?(CGPoint).should == true
+ CGPointEqualToPoint(point, CGPointMake(110, 220)).should == true
+ end
+ end
+
describe "#center" do
it "works" do
point = CGRect.make(width: 100, height: 100).center
point.is_a?(CGPoint).should == true
CGPointEqualToPoint(point, CGPointMake(50, 50)).should == true
@@ -300,9 +398,23 @@
outer_rect = CGRect.make(x: 20, y: 30, width: 100, height: 100)
inner_rect = CGRect.make(width: 50, height: 50)
centered_rect = inner_rect.centered_in(outer_rect, true)
CGRectEqualToRect(centered_rect, CGRectMake(45, 55, 50, 50)).should == true
+ end
+ end
+
+ describe "#- (unary)" do
+ it "should work" do
+ rect = CGRect.make(x: 10, y:10, width: 100, height: 200)
+ (-rect).should == CGRect.new([-10, -10], [-100, -200])
+ end
+ end
+
+ describe "#- (binary)" do
+ it "should work" do
+ rect = CGRect.make(x: 10, y:10, width: 100, height: 200)
+ (rect - rect).should == CGRect.new([-110, -210], [220, 420])
end
end
describe "#+" do
it "works with CGRect" do
\ No newline at end of file