summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Primitives/BoundingRectangleTests.cs
blob: 6f95cf5732d69886453ccab52508e8cb303a94ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
//using System.Collections.Generic;
//using System.Globalization;
//using Microsoft.Xna.Framework;
//using Xunit;

//namespace MonoGame.Extended.Tests.Primitives
//{
//    
//    public class BoundingRectangleTests
//    {
//        public IEnumerable<TestCaseData> ConstructorTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Point2(), new Vector2()).SetName(
//                        "The empty bounding rectangle has the expected position and radii.");
//                yield return
//                    new TestCaseData(new Point2(5, 5), new Vector2(15, 15)).SetName(
//                        "A non-empty bounding rectangle has the expected position and radii.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(ConstructorTestCases))]
//        public void Constructor(Point2 centre, Vector2 radii)
//        {
//            var boundingRectangle = new BoundingRectangle(centre, radii);
//            Assert.Equal(centre, boundingRectangle.Center);
//            Assert.Equal(radii, boundingRectangle.HalfExtents);
//        }

//        public IEnumerable<TestCaseData> CreateFromMinimumMaximumTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Point2(), new Point2(), new BoundingRectangle()).SetName(
//                        "The bounding rectangle created from the zero minimum point and zero maximum point is the empty bounding rectangle.")
//                    ;
//                yield return
//                    new TestCaseData(new Point2(5, 5), new Point2(15, 15),
//                        new BoundingRectangle(new Point2(10, 10), new Size2(5, 5))).SetName(
//                        "The bounding rectangle created from the non-zero minimum point and the non-zero maximum point is the expected bounding rectangle.")
//                    ;
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(CreateFromMinimumMaximumTestCases))]
//        public void CreateFromMinimumMaximum(Point2 minimum, Point2 maximum, BoundingRectangle expectedBoundingRectangle)
//        {
//            var actualBoundingRectangle = BoundingRectangle.CreateFrom(minimum, maximum);
//            Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
//        }

//        public IEnumerable<TestCaseData> CreateFromPointsTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(null, new BoundingRectangle()).SetName(
//                        "The bounding rectangle created from null points is the empty bounding rectangle.");
//                yield return
//                    new TestCaseData(new Point2[0], new BoundingRectangle()).SetName(
//                        "The bounding rectangle created from the empty set of points is the empty bounding rectangle.");
//                yield return
//                    new TestCaseData(
//                        new[]
//                        {
//                            new Point2(5, 5), new Point2(10, 10), new Point2(15, 15), new Point2(-5, -5),
//                            new Point2(-15, -15)
//                        }, new BoundingRectangle(new Point2(0, 0), new Size2(15, 15))).SetName(
//                        "The bounding rectangle created from a non-empty set of points is the expected bounding rectangle.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(CreateFromPointsTestCases))]
//        public void CreateFromPoints(Point2[] points, BoundingRectangle expectedBoundingRectangle)
//        {
//            var actualBoundingRectangle = BoundingRectangle.CreateFrom(points);
//            Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
//        }

//        public IEnumerable<TestCaseData> CreateFromTransformedTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), Matrix2.Identity, new BoundingRectangle()).SetName(
//                        "The bounding rectangle created from the empty bounding rectangle transformed by the identity matrix is the empty bounding rectangle.")
//                    ;
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Size2(20, 20)), Matrix2.CreateScale(2), new BoundingRectangle(new Point2(0, 0), new Size2(40, 40))).SetName(
//                        "The bounding rectangle created from a non-empty bounding rectangle transformed by a non-identity matrix is the expected bounding rectangle.")
//                    ;
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(CreateFromTransformedTestCases))]
//        public void CreateFromTransformed(BoundingRectangle boundingRectangle, Matrix2 transformMatrix,
//            BoundingRectangle expectedBoundingRectangle)
//        {
//            var actualBoundingRectangle = BoundingRectangle.Transform(boundingRectangle, ref transformMatrix);
//            Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
//        }

//        public IEnumerable<TestCaseData> UnionTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), new BoundingRectangle()).SetName(
//                        "The union of two empty bounding rectangles is the empty bounding rectangle.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Size2(15, 15)),
//                            new BoundingRectangle(new Point2(20, 20), new Size2(40, 40)), new BoundingRectangle(new Point2(20, 20), new Size2(40, 40)))
//                        .SetName(
//                            "The union of two non-empty bounding rectangles is the expected bounding rectangle.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(UnionTestCases))]
//        public void Union(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, BoundingRectangle expectedBoundingRectangle)
//        {
//            Assert.Equal(expectedBoundingRectangle, boundingRectangle1.Union(boundingRectangle2));
//            Assert.Equal(expectedBoundingRectangle, BoundingRectangle.Union(boundingRectangle1, boundingRectangle2));
//        }

//        public IEnumerable<TestCaseData> IntersectionTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), new BoundingRectangle()).SetName(
//                        "The intersection of two empty bounding rectangles is the empty bounding box.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(-10, -10), new Size2(15, 15)),
//                        new BoundingRectangle(new Point2(20, 20), new Size2(40, 40)),
//                        new BoundingRectangle(new Point2(-7.5f, -7.5f), new Size2(12.5f, 12.5f))).SetName(
//                        "The intersection of two overlapping non-empty bounding rectangles is the expected bounding rectangle.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(-30, -30), new Size2(15, 15)),
//                        new BoundingRectangle(new Point2(20, 20), new Size2(10, 10)),
//                        BoundingRectangle.Empty).SetName(
//                        "The intersection of two non-overlapping non-empty bounding rectangles is the empty bounding rectangle.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(IntersectionTestCases))]
//        public void Intersection(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2,
//            BoundingRectangle? expectedBoundingRectangle)
//        {
//            Assert.Equal(expectedBoundingRectangle, boundingRectangle1.Intersection(boundingRectangle2));
//            Assert.Equal(expectedBoundingRectangle, BoundingRectangle.Intersection(boundingRectangle1, boundingRectangle2));
//        }

//        public IEnumerable<TestCaseData> IntersectsTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), true).SetName(
//                        "Two empty bounding rectangles intersect.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(-10, -10), new Size2(15, 15)),
//                        new BoundingRectangle(new Point2(20, 20), new Size2(40, 40)), true).SetName(
//                        "Two overlapping non-empty bounding rectangles intersect.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(-40, -50), new Size2(15, 15)),
//                        new BoundingRectangle(new Point2(20, 20), new Size2(15, 15)), false).SetName(
//                        "Two non-overlapping non-empty bounding rectangles do not intersect.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(IntersectsTestCases))]
//        public void Intersects(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedToIntersect)
//        {
//            Assert.Equal(expectedToIntersect, boundingRectangle1.Intersects(boundingRectangle2));
//            Assert.Equal(expectedToIntersect, BoundingRectangle.Intersects(boundingRectangle1, boundingRectangle2));
//        }

//        public IEnumerable<TestCaseData> ContainsPointTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new Point2(), true).SetName(
//                        "The empty bounding rectangle contains the zero point.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Size2(15, 15)), new Point2(-15, -15), true)
//                        .SetName(
//                            "A non-empty bounding rectangle contains a point inside it.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Size2(15, 15)), new Point2(-16, 15), false)
//                        .SetName(
//                            "A non-empty bounding rectangle does not contain a point outside it.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(ContainsPointTestCases))]
//        public void ContainsPoint(BoundingRectangle boundingRectangle, Point2 point, bool expectedToContainPoint)
//        {
//            Assert.Equal(expectedToContainPoint, boundingRectangle.Contains(point));
//            Assert.Equal(expectedToContainPoint, BoundingRectangle.Contains(boundingRectangle, point));
//        }

//        public IEnumerable<TestCaseData> ClosestPointTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new Point2(), new Point2()).SetName(
//                        "The closest point on the empty bounding rectangle to the zero point is the zero point.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Point2(50, 50)), new Point2(25, 25),
//                        new Point2(25, 25)).SetName(
//                        "The closest point on a non-empty bounding rectangle to a point which is inside the bounding rectangle is that point.")
//                    ;
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Point2(50, 50)), new Point2(400, 0),
//                        new Point2(50, 0)).SetName(
//                        "The closest point on a non-empty bounding rectangle to a point which is outside the bounding rectangle is the expected point.")
//                    ;
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(ClosestPointTestCases))]
//        public void ClosestPoint(BoundingRectangle boundingRectangle, Point2 point, Point2 expectedClosestPoint)
//        {
//            var actualClosestPoint = boundingRectangle.ClosestPointTo(point);
//            Assert.Equal(expectedClosestPoint, actualClosestPoint);
//        }

//        public IEnumerable<TestCaseData> EqualityTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), true).SetName(
//                        "Empty bounding rectangles are equal.")
//                    ;
//                yield return
//                    new TestCaseData(
//                        new BoundingRectangle(new Point2(0, 0), new Size2(float.MaxValue, float.MinValue)),
//                        new BoundingRectangle(new Point2(0, 0),
//                            new Point2(float.MinValue, float.MaxValue)), false).SetName(
//                        "Two different non-empty bounding rectangles are not equal.");
//                yield return
//                    new TestCaseData(
//                        new BoundingRectangle(new Point2(0, 0), new Size2(float.MinValue, float.MaxValue)),
//                        new BoundingRectangle(new Point2(0, 0),
//                            new Size2(float.MinValue, float.MaxValue)), true).SetName(
//                        "Two identical non-empty bounding rectangles are equal.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(EqualityTestCases))]
//        public void Equality(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedToBeEqual)
//        {
//            Assert.IsTrue(Equals(boundingRectangle1, boundingRectangle2) == expectedToBeEqual);
//            Assert.IsTrue(boundingRectangle1 == boundingRectangle2 == expectedToBeEqual);
//            Assert.IsFalse(boundingRectangle1 == boundingRectangle2 != expectedToBeEqual);
//            Assert.IsTrue(boundingRectangle1.Equals(boundingRectangle2) == expectedToBeEqual);

//            if (expectedToBeEqual)
//                Assert.Equal(boundingRectangle1.GetHashCode(), boundingRectangle2.GetHashCode());
//        }

//        public IEnumerable<TestCaseData> InequalityTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), null, false).SetName(
//                        "A bounding rectangle is not equal to a null object.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new object(), false).SetName(
//                        "A bounding rectangle is not equal to an instantiated object.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(InequalityTestCases))]
//        public void Inequality(BoundingRectangle boundingRectangle, object obj, bool expectedToBeEqual)
//        {
//            Assert.IsTrue(boundingRectangle.Equals(obj) == expectedToBeEqual);
//        }

//        public IEnumerable<TestCaseData> HashCodeTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), true).SetName(
//                        "Two empty bounding rectangles have the same hash code.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Size2(50, 50)),
//                        new BoundingRectangle(new Point2(0, 0), new Size2(50, 50)), true).SetName(
//                        "Two indentical non-empty bounding rectangles have the same hash code.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(0, 0), new Size2(50, 50)),
//                        new BoundingRectangle(new Point2(50, 50), new Size2(50, 50)), false).SetName(
//                        "Two different non-empty bounding rectangles do not have the same hash code.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(HashCodeTestCases))]
//        public void HashCode(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedThatHashCodesAreEqual)
//        {
//            var hashCode1 = boundingRectangle1.GetHashCode();
//            var hashCode2 = boundingRectangle2.GetHashCode();
//            if (expectedThatHashCodesAreEqual)
//                Assert.Equal(hashCode1, hashCode2);
//            else
//                Assert.AreNotEqual(hashCode1, hashCode2);
//        }

//        public IEnumerable<TestCaseData> ToRectangleTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(), new Rectangle()).SetName(
//                        "The empty bounding rectangle point converted to a rectangle is the empty rectangle.");
//                yield return
//                    new TestCaseData(new BoundingRectangle(new Point2(25, 25), new Size2(25, 25)),
//                        new Rectangle(0, 0, 50, 50)).SetName(
//                        "A non-empty bounding rectangle converted to a rectangle is the expected rectangle.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(ToRectangleTestCases))]
//        public void ToRectangle(BoundingRectangle boundingRectangle, Rectangle expectedRectangle)
//        {
//            var actualRectangle = (Rectangle)boundingRectangle;
//            Assert.Equal(expectedRectangle, actualRectangle);
//        }

//        public IEnumerable<TestCaseData> FromRectangleTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Rectangle(), new BoundingRectangle()).SetName(
//                        "The empty rectangle converted to a bounding rectangle is the empty bounding rectangle.");
//                yield return
//                    new TestCaseData(new Rectangle(0, 0, 50, 50),
//                        new BoundingRectangle(new Point2(25, 25), new Size2(25, 25))).SetName(
//                        "A non-empty rectangle converted to a bounding rectangle is the expected bounding rectangle.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(FromRectangleTestCases))]
//        public void FromRectangle(Rectangle rectangle, BoundingRectangle expectedBoundingRectangle)
//        {
//            var actualBoundingRectangle = (BoundingRectangle)rectangle;
//            Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
//        }

//        public IEnumerable<TestCaseData> StringCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new BoundingRectangle(),
//                        string.Format(CultureInfo.CurrentCulture, "Centre: {0}, Radii: {1}", new Point2(),
//                            new Vector2())).SetName(
//                        "The empty bounding rectangle has the expected string representation using the current culture.");
//                yield return new TestCaseData(new BoundingRectangle(new Point2(5.1f, -5.123f), new Size2(5.4f, -5.4123f)),
//                    string.Format(CultureInfo.CurrentCulture, "Centre: {0}, Radii: {1}", new Point2(5.1f, -5.123f),
//                        new Vector2(5.4f, -5.4123f))).SetName(
//                    "A non-empty bounding rectangle has the expected string representation using the current culture.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(StringCases))]
//        public void String(BoundingRectangle boundingRectangle, string expectedString)
//        {
//            var actualString = boundingRectangle.ToString();
//            Assert.Equal(expectedString, actualString);
//        }
//    }
//}