@@ -98,6 +98,32 @@ public void DimensionsTest(int x, int y, int width, int height)
9898 Assert . Equal ( y + height , rect . Bottom ) ;
9999 }
100100
101+ [ Theory ]
102+ [ InlineData ( 0 , 0 ) ]
103+ [ InlineData ( int . MaxValue , int . MinValue ) ]
104+ public static void LocationSetTest ( int x , int y )
105+ {
106+ var point = new Point ( x , y ) ;
107+ var rect = new Rectangle ( 10 , 10 , 10 , 10 ) ;
108+ rect . Location = point ;
109+ Assert . Equal ( point , rect . Location ) ;
110+ Assert . Equal ( point . X , rect . X ) ;
111+ Assert . Equal ( point . Y , rect . Y ) ;
112+ }
113+
114+ [ Theory ]
115+ [ InlineData ( 0 , 0 ) ]
116+ [ InlineData ( int . MaxValue , int . MinValue ) ]
117+ public static void SizeSetTest ( int x , int y )
118+ {
119+ var size = new Size ( x , y ) ;
120+ var rect = new Rectangle ( 10 , 10 , 10 , 10 ) ;
121+ rect . Size = size ;
122+ Assert . Equal ( size , rect . Size ) ;
123+ Assert . Equal ( size . Width , rect . Width ) ;
124+ Assert . Equal ( size . Height , rect . Height ) ;
125+ }
126+
101127 [ Theory ]
102128 [ InlineData ( int . MaxValue , int . MinValue , int . MaxValue , int . MinValue ) ]
103129 [ InlineData ( int . MaxValue , 0 , int . MinValue , 0 ) ]
@@ -113,6 +139,27 @@ public void EqualityTest(int x, int y, int width, int height)
113139 Assert . False ( rect1 . Equals ( rect2 ) ) ;
114140 }
115141
142+ [ Fact ]
143+ public static void EqualityTest_NotRectangle ( )
144+ {
145+ var rectangle = new Rectangle ( 0 , 0 , 0 , 0 ) ;
146+ Assert . False ( rectangle . Equals ( null ) ) ;
147+ Assert . False ( rectangle . Equals ( 0 ) ) ;
148+ Assert . False ( rectangle . Equals ( new RectangleF ( 0 , 0 , 0 , 0 ) ) ) ;
149+ }
150+
151+ [ Fact ]
152+ public static void GetHashCodeTest ( )
153+ {
154+ var rect1 = new Rectangle ( 10 , 10 , 10 , 10 ) ;
155+ var rect2 = new Rectangle ( 10 , 10 , 10 , 10 ) ;
156+ Assert . Equal ( rect1 . GetHashCode ( ) , rect2 . GetHashCode ( ) ) ;
157+ Assert . NotEqual ( rect1 . GetHashCode ( ) , new Rectangle ( 20 , 10 , 10 , 10 ) . GetHashCode ( ) ) ;
158+ Assert . NotEqual ( rect1 . GetHashCode ( ) , new Rectangle ( 10 , 20 , 10 , 10 ) . GetHashCode ( ) ) ;
159+ Assert . NotEqual ( rect1 . GetHashCode ( ) , new Rectangle ( 10 , 10 , 20 , 10 ) . GetHashCode ( ) ) ;
160+ Assert . NotEqual ( rect1 . GetHashCode ( ) , new Rectangle ( 10 , 10 , 10 , 20 ) . GetHashCode ( ) ) ;
161+ }
162+
116163 [ Theory ]
117164 [ InlineData ( float . MaxValue , float . MinValue , float . MaxValue , float . MinValue ) ]
118165 [ InlineData ( float . MinValue , float . MaxValue , float . MinValue , float . MaxValue ) ]
@@ -154,6 +201,8 @@ public void InflateTest(int x, int y, int width, int height)
154201 Rectangle rect = new Rectangle ( x , y , width , height ) ;
155202 Rectangle inflatedRect = new Rectangle ( x - width , y - height , width + 2 * width , height + 2 * height ) ;
156203
204+ Assert . Equal ( inflatedRect , Rectangle . Inflate ( rect , width , height ) ) ;
205+
157206 rect . Inflate ( width , height ) ;
158207 Assert . Equal ( inflatedRect , rect ) ;
159208
@@ -177,6 +226,16 @@ public void IntersectTest(int x, int y, int width, int height)
177226 Assert . False ( rect . IntersectsWith ( expectedRect ) ) ;
178227 }
179228
229+ [ Fact ]
230+ public static void Intersect_IntersectingRects_Test ( )
231+ {
232+ var rect1 = new Rectangle ( 0 , 0 , 5 , 5 ) ;
233+ var rect2 = new Rectangle ( 1 , 1 , 3 , 3 ) ;
234+ var expected = new Rectangle ( 1 , 1 , 3 , 3 ) ;
235+
236+ Assert . Equal ( expected , Rectangle . Intersect ( rect1 , rect2 ) ) ;
237+ }
238+
180239 [ Theory ]
181240 [ InlineData ( 0 , 0 , 0 , 0 ) ]
182241 [ InlineData ( int . MaxValue , int . MinValue , int . MinValue , int . MaxValue ) ]
@@ -216,11 +275,13 @@ public void OffsetTest(int x, int y, int width, int height)
216275 Assert . Equal ( expectedRect , r1 ) ;
217276 }
218277
219- [ Fact ]
220- public void ToStringTest ( )
278+ [ Theory ]
279+ [ InlineData ( 0 , 0 , 0 , 0 ) ]
280+ [ InlineData ( 5 , - 5 , 0 , 1 ) ]
281+ public void ToStringTest ( int x , int y , int width , int height )
221282 {
222- string expected = "{X=0,Y=0,Width=0,Height=0}" ;
223- Assert . Equal ( expected , Rectangle . Empty . ToString ( ) ) ;
283+ var r = new Rectangle ( x , y , width , height ) ;
284+ Assert . Equal ( string . Format ( CultureInfo . CurrentCulture , "{{X={0},Y={1},Width={2},Height={3}}}" , r . X , r . Y , r . Width , r . Height ) , r . ToString ( ) ) ;
224285 }
225286 }
226287}
0 commit comments