summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/tests/MonoGame.Extended.Tests/Primitives/Segment2DTests.cs
blob: b99452735ea8f973a8052a9323df0b15cff64389 (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
//using System.Collections.Generic;
//using System.Globalization;
//using Xunit;

//namespace MonoGame.Extended.Tests.Primitives
//{
//    public class Segment2DTests
//    {
//        public IEnumerable<TestCaseData> ConstructorTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Point2(), new Point2()).SetName(
//                        "The empty segment has expected starting and ending points.");
//                yield return
//                    new TestCaseData(
//                        new Point2(float.MaxValue, float.MinValue),
//                        new Point2(int.MaxValue, int.MinValue)).SetName(
//                        "A non-empty segment has the expected starting and ending points.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(ConstructorTestCases))]
//        public void Constructor(Point2 startingPoint, Point2 endingPoint)
//        {
//            var segment = new Segment2(startingPoint, endingPoint);
//            Assert.Equal(startingPoint, segment.Start);
//            Assert.Equal(endingPoint, segment.End);
//        }

//        public IEnumerable<TestCaseData> ClosestPointTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Segment2(), new Point2(), new Point2()).SetName(
//                        "The closest point on the empty segment to the zero point is the zero point.");
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(200, 0)), new Point2(-100, 200),
//                        new Point2(0, 0)).SetName(
//                        "The closest point on a non-empty segment to a point which is projected beyond the start of the segment is the segment's starting point.")
//                    ;
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(200, 0)), new Point2(400, 200),
//                        new Point2(200, 0)).SetName(
//                        "The closest point on a non-empty segment to a point which is projected beyond the end of the segment is the segment's ending point.")
//                    ;
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(200, 0)), new Point2(100, 200),
//                        new Point2(100, 0)).SetName(
//                        "The closest point on a non-empty segment to a point which is projected inside the segment is the projected point.")
//                    ;
//            }
//        }

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

//        public IEnumerable<TestCaseData> SquaredDistanceToPointTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Segment2(), new Point2(), 0).SetName(
//                        "The squared distance of the zero point to the empty segment is 0.");
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(20, 0)), new Point2(-10, 20), 500)
//                        .SetName(
//                            "The squared distance of a point projected beyond the start of a non-empty segment is the squared distance from the segment's starting point to the point.")
//                    ;
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(20, 0)), new Point2(40, 20), 400)
//                        .SetName(
//                            "The squared distance of a point projected beyond the end of a non-empty segment is the squared distance from the segment's ending point to the point.")
//                    ;
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(20, 0)), new Point2(10, 25), 625).SetName
//                    (
//                        "The squared distance of a point projected inside a non-empty segment is the squared distance from the projected point to the point.")
//                    ;
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(SquaredDistanceToPointTestCases))]
//        public void SquaredDistanceToPoint(Segment2 segment, Point2 point,
//            float expectedDistance)
//        {
//            var actualDistance = segment.SquaredDistanceTo(point);
//            Assert.Equal(expectedDistance, actualDistance);
//        }

//        public IEnumerable<TestCaseData> IntersectsBoundingRectangleTestCases
//        {
//            get
//            {
//                yield return
//                    new TestCaseData(new Segment2(), new BoundingRectangle(), true, Point2.Zero).SetName(
//                        "The empty segment intersects the empty bounding box.");
//                yield return
//                    new TestCaseData(new Segment2(new Point2(-75, -75), new Point2(75, -75)),
//                        new BoundingRectangle(new Point2(), new Size2(50, 50)), false, Point2.NaN).SetName(
//                        "A non-empty segment outside a non-empty bounding box does not intersect the bounding box.");
//                yield return
//                    new TestCaseData(new Segment2(new Point2(0, 0), new Point2(25, 0)), new BoundingRectangle(new Point2(), new Size2(50, 50)),
//                        true, new Point2(0, 0)).SetName(
//                        "A non-empty segment inside a non-empty bounding box intersects the bounding box.");
//                yield return
//                    new TestCaseData(new Segment2(new Point2(-100, 0), new Point2(100, 0)),
//                        new BoundingRectangle(new Point2(), new Size2(50, 50)),
//                        true, new Point2(-50, 0)).SetName(
//                        "A non-empty segment crossing a non-empty bounding box intersects the bounding box.");
//            }
//        }

//        [Fact]
//        [TestCaseSource(nameof(IntersectsBoundingRectangleTestCases))]
//        public void IntersectsBoundingRectangle(Segment2 segment, BoundingRectangle boundingRectangle, bool expectedResult,
//            Point2 expectedIntersectionPoint)
//        {
//            Point2 actualIntersectionPoint;
//            var actualResult = segment.Intersects(boundingRectangle, out actualIntersectionPoint);
//            Assert.Equal(expectedResult, actualResult);

//            if (actualResult)
//            {
//                Assert.Equal(expectedIntersectionPoint, actualIntersectionPoint);
//            }
//            else
//            {
//                Assert.IsTrue(float.IsNaN(actualIntersectionPoint.X));
//                Assert.IsTrue(float.IsNaN(actualIntersectionPoint.Y));
//            }
//        }

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

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

//            if (expectedToBeEqual)
//                Assert.Equal(segment1.GetHashCode(), segment2.GetHashCode());
//        }

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

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

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

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

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

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