@@ -203,6 +203,33 @@ final class CoreGraphicsTests: XCTestCase {
203
203
XCTAssertFalse ( r4. intersects ( r1) )
204
204
}
205
205
206
+ func testRectUnion( ) {
207
+ let r1 : Rect = Rect ( x: 0 , y: 0 , width: 50 , height: 50 )
208
+ let r2 : Rect = Rect ( x: 25 , y: 25 , width: 50 , height: 50 )
209
+ let r3 : Rect = Rect ( x: 100 , y: 100 , width: 50 , height: 50 )
210
+ let r4 : Rect = Rect ( x: 75 , y: 75 , width: - 50 , height: - 50 )
211
+
212
+ XCTAssertEqual ( r1. union ( r2) , Rect ( x: 0 , y: 0 , width: 75 , height: 75 ) )
213
+ XCTAssertEqual ( r2. union ( r1) , Rect ( x: 0 , y: 0 , width: 75 , height: 75 ) )
214
+
215
+ XCTAssertEqual ( Rect . null. union ( r1) , Rect ( x: 0 , y: 0 , width: 50 , height: 50 ) )
216
+ XCTAssertEqual ( r1. union ( Rect . null) , Rect ( x: 0 , y: 0 , width: 50 , height: 50 ) )
217
+
218
+ XCTAssertEqual ( r1. union ( r3) , Rect ( x: 0 , y: 0 , width: 150 , height: 150 ) )
219
+ XCTAssertEqual ( r3. union ( r1) , Rect ( x: 0 , y: 0 , width: 150 , height: 150 ) )
220
+
221
+ XCTAssertEqual ( r1. union ( r4) , Rect ( x: 0 , y: 0 , width: 75 , height: 75 ) )
222
+ XCTAssertEqual ( r4. union ( r1) , Rect ( x: 0 , y: 0 , width: 75 , height: 75 ) )
223
+
224
+ XCTAssertEqual ( Rect . zero. union ( Rect . zero) , Rect . zero)
225
+
226
+ XCTAssertEqual ( Rect . infinite. union ( Rect . zero) , Rect . infinite)
227
+ XCTAssertEqual ( Rect . zero. union ( Rect . infinite) , Rect . infinite)
228
+
229
+ XCTAssertEqual ( Rect . infinite. union ( Rect . null) , Rect . infinite)
230
+ XCTAssertEqual ( Rect . null. union ( Rect . infinite) , Rect . infinite)
231
+ }
232
+
206
233
func testRectNonstandardEquality( ) {
207
234
let r1 : Rect = Rect ( x: 0 , y: 0 , width: 10 , height: 10 )
208
235
let r2 : Rect = Rect ( x: 10 , y: 10 , width: - 10 , height: - 10 )
@@ -229,6 +256,7 @@ final class CoreGraphicsTests: XCTestCase {
229
256
( " testRectInsetBy " , testRectInsetBy) ,
230
257
( " testRectIntersection " , testRectIntersection) ,
231
258
( " testRectIntersects " , testRectIntersects) ,
259
+ ( " testRectUnion " , testRectUnion) ,
232
260
( " testRectNonstandardEquality " , testRectNonstandardEquality) ,
233
261
]
234
262
}
0 commit comments