[squeak-dev] The Trunk: GraphicsTests-nice.24.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Jun 20 21:05:15 UTC 2010

Nicolas Cellier uploaded a new version of GraphicsTests to project The Trunk:
http://source.squeak.org/trunk/GraphicsTests-nice.24.mcz

==================== Summary ====================

Name: GraphicsTests-nice.24
Author: nice
Time: 20 June 2010, 11:05:21.594 pm
UUID: d6cc2cfd-2790-344f-bc46-9a82f91a88dd
Ancestors: GraphicsTests-wiz.23

A few more tests of Rectangle functions, including behaviour of empty rectangles

=============== Diff against GraphicsTests-wiz.23 ===============

+ ----- Method: RectangleTest>>testCenterEmpty (in category 'testing') -----
+ testCenterEmpty
+ 	| r1 c |
+ 	r1 := 30 at 10 corner: 10 at 20.
+ 	c := r1 center.
+ 	self deny: (r1 containsPoint: c) description: 'An empty rectangle does not contain any point.'.
+ 	self assert: (r1 topLeft dist: c) = (r1 bottomRight dist: c).
+ 	self assert: (r1 bottomLeft dist: c) = (r1 topRight dist: c).
+ 	self assert: (r1 topLeft dist: c) = (r1 bottomLeft dist: c).
+ 	self assert: (r1 translateBy: -20 at 10) center = (c translateBy: -20 at 10) description: 'the center is translated with the rectangle'.!

+ ----- Method: RectangleTest>>testFlipEmpty (in category 'testing') -----
+ testFlipEmpty
+ 	| r1 c r1Horiz r1Vert |
+ 	r1 := 30 at 10 corner: 10 at 20.
+ 	c := 5 at 5.
+ 	r1Horiz := r1 flipBy: #horizontal centerAt: c.
+ 	r1Vert := r1 flipBy: #vertical centerAt: c.
+
+ 	self assert: r1 area = r1Horiz area description: 'flip preserves area'.
+ 	self assert: r1 area = r1Vert area description: 'flip preserves area'.
+
+ 	self assert: r1 extent = r1Horiz extent description: 'flip preserves extent'.
+ 	self assert: r1 extent = r1Vert extent description: 'flip preserves extent'.
+
+ 	self assert:  (r1 flipBy: #horizontal centerAt: r1 center) = r1.
+ 	self assert:  (r1 flipBy: #vertical centerAt: r1 center) = r1!

+ ----- Method: RectangleTest>>testFlip (in category 'testing') -----
+ testFlip
+ 	| r1 c r1Horiz r1Vert |
+ 	r1 := 30 at 10 extent: 10 at 20.
+ 	c := 5 at 5.
+ 	r1Horiz := r1 flipBy: #horizontal centerAt: c.
+ 	r1Vert := r1 flipBy: #vertical centerAt: c.
+
+ 	self assert: r1 area = r1Horiz area description: 'flip preserves area'.
+ 	self assert: r1 area = r1Vert area description: 'flip preserves area'.
+
+ 	self assert: r1 extent = r1Horiz extent description: 'flip preserves extent'.
+ 	self assert: r1 extent = r1Vert extent description: 'flip preserves extent'.
+
+ 	self assert:  (r1 flipBy: #horizontal centerAt: r1 center) = r1.
+ 	self assert:  (r1 flipBy: #vertical centerAt: r1 center) = r1!

+ ----- Method: RectangleTest>>testArea (in category 'testing') -----
+ testArea
+ 	| r1 empty |
+ 	r1 := 0 at 0 extent: 10 at 20.
+ 	self assert: r1 area = (10*20).
+ 	self assert: (r1 translateBy: -20 at 10) area = (10*20) description: 'translation preserves area'.
+
+ 	empty := 10 at 20 corner: 0 at 0.
+ 	self assert: empty area = 0 description: 'the area of an empty rectangle is null'.
+ 	empty := 10 at 0 corner: 0 at 20.
+ 	self assert: empty area = 0 description: 'the area of an empty rectangle is null'.
+ 	empty := 0 at 20 corner: 10 at 0.
+ 	self assert: empty area = 0 description: 'the area of an empty rectangle is null'.!

+ ----- Method: RectangleTest>>testRotateEmpty (in category 'testing') -----
+ testRotateEmpty
+ 	| r1 c r1Left r1Right r1Pi |
+ 	r1 := 30 at 10 corner: 10 at 20.
+ 	c := 5 at 5.
+ 	r1Left := r1 rotateBy: #left centerAt: c.
+ 	r1Right := r1 rotateBy: #right centerAt: c.
+ 	r1Pi := r1 rotateBy: #pi centerAt: c.
+
+ 	self assert: r1 area = r1Left area description: 'rotation preserves area'.
+ 	self assert: r1 area = r1Right area description: 'rotation preserves area'.
+ 	self assert: r1 area = r1Pi area description: 'rotation preserves area'.
+
+ 	self assert: r1 extent transposed = r1Left extent.
+ 	self assert: r1 extent transposed = r1Right extent.
+ 	self assert: r1 extent = r1Pi extent.
+
+ 	self assert:  (r1 rotateBy: #pi centerAt: r1 center) = r1!

+ ----- Method: RectangleTest>>testCenter (in category 'testing') -----
+ testCenter
+ 	| r1 c |
+ 	r1 := 0 at 0 extent: 10 at 20.
+ 	c := r1 center.
+ 	self assert: (r1 containsPoint: c) description: 'the center is inside the rectangle'.
+ 	self assert: (r1 topLeft dist: c) = (r1 bottomRight dist: c).
+ 	self assert: (r1 bottomLeft dist: c) = (r1 topRight dist: c).
+ 	self assert: (r1 topLeft dist: c) = (r1 bottomLeft dist: c).
+ 	self assert: (r1 translateBy: -20 at 10) center = (c translateBy: -20 at 10) description: 'the center is translated with the rectangle'.!

+ ----- Method: RectangleTest>>testRotate (in category 'testing') -----
+ testRotate
+ 	| r1 c r1Left r1Right r1Pi |
+ 	r1 := 30 at 10 extent: 10 at 20.
+ 	c := 5 at 5.
+ 	r1Left := r1 rotateBy: #left centerAt: c.
+ 	r1Right := r1 rotateBy: #right centerAt: c.
+ 	r1Pi := r1 rotateBy: #pi centerAt: c.
+
+ 	self assert: r1 area = r1Left area description: 'rotation preserves area'.
+ 	self assert: r1 area = r1Right area description: 'rotation preserves area'.
+ 	self assert: r1 area = r1Pi area description: 'rotation preserves area'.
+
+ 	self assert: r1 extent transposed = r1Left extent.
+ 	self assert: r1 extent transposed = r1Right extent.
+ 	self assert: r1 extent = r1Pi extent.
+
+ 	self assert:  (r1 rotateBy: #pi centerAt: r1 center) = r1!

+ ----- Method: RectangleTest>>testIntersectionEmpty (in category 'testing') -----
+ testIntersectionEmpty
+ 	| rect1 empty1 empty2 |
+ 	rect1 := 10 at 10 corner: 40 at 40.
+ 	empty1 := 50 at 50 corner: 0 at 0.
+ 	empty2 := 30 at 30 corner: 20 at 20.
+ 	self
+ 		deny: (rect1 intersects: empty1);
+ 		deny: (rect1 intersects: empty2);
+ 		deny: (empty1 intersects: rect1);
+ 		deny: (empty2 intersects: rect1);
+ 		deny: (empty1 intersects: empty2);
+ 		deny: (empty2 intersects: empty1).!