BoundingRectangleTests.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. //using System.Collections.Generic;
  2. //using System.Globalization;
  3. //using Microsoft.Xna.Framework;
  4. //using Xunit;
  5. //namespace MonoGame.Extended.Tests.Primitives
  6. //{
  7. //
  8. // public class BoundingRectangleTests
  9. // {
  10. // public IEnumerable<TestCaseData> ConstructorTestCases
  11. // {
  12. // get
  13. // {
  14. // yield return
  15. // new TestCaseData(new Vector2(), new Vector2()).SetName(
  16. // "The empty bounding rectangle has the expected position and radii.");
  17. // yield return
  18. // new TestCaseData(new Vector2(5, 5), new Vector2(15, 15)).SetName(
  19. // "A non-empty bounding rectangle has the expected position and radii.");
  20. // }
  21. // }
  22. // [Fact]
  23. // [TestCaseSource(nameof(ConstructorTestCases))]
  24. // public void Constructor(Vector2 centre, Vector2 radii)
  25. // {
  26. // var boundingRectangle = new BoundingRectangle(centre, radii);
  27. // Assert.Equal(centre, boundingRectangle.Center);
  28. // Assert.Equal(radii, boundingRectangle.HalfExtents);
  29. // }
  30. // public IEnumerable<TestCaseData> CreateFromMinimumMaximumTestCases
  31. // {
  32. // get
  33. // {
  34. // yield return
  35. // new TestCaseData(new Vector2(), new Vector2(), new BoundingRectangle()).SetName(
  36. // "The bounding rectangle created from the zero minimum point and zero maximum point is the empty bounding rectangle.")
  37. // ;
  38. // yield return
  39. // new TestCaseData(new Vector2(5, 5), new Vector2(15, 15),
  40. // new BoundingRectangle(new Vector2(10, 10), new Size2(5, 5))).SetName(
  41. // "The bounding rectangle created from the non-zero minimum point and the non-zero maximum point is the expected bounding rectangle.")
  42. // ;
  43. // }
  44. // }
  45. // [Fact]
  46. // [TestCaseSource(nameof(CreateFromMinimumMaximumTestCases))]
  47. // public void CreateFromMinimumMaximum(Vector2 minimum, Vector2 maximum, BoundingRectangle expectedBoundingRectangle)
  48. // {
  49. // var actualBoundingRectangle = BoundingRectangle.CreateFrom(minimum, maximum);
  50. // Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
  51. // }
  52. // public IEnumerable<TestCaseData> CreateFromPointsTestCases
  53. // {
  54. // get
  55. // {
  56. // yield return
  57. // new TestCaseData(null, new BoundingRectangle()).SetName(
  58. // "The bounding rectangle created from null points is the empty bounding rectangle.");
  59. // yield return
  60. // new TestCaseData(new Vector2[0], new BoundingRectangle()).SetName(
  61. // "The bounding rectangle created from the empty set of points is the empty bounding rectangle.");
  62. // yield return
  63. // new TestCaseData(
  64. // new[]
  65. // {
  66. // new Vector2(5, 5), new Vector2(10, 10), new Vector2(15, 15), new Vector2(-5, -5),
  67. // new Vector2(-15, -15)
  68. // }, new BoundingRectangle(new Vector2(0, 0), new Size2(15, 15))).SetName(
  69. // "The bounding rectangle created from a non-empty set of points is the expected bounding rectangle.");
  70. // }
  71. // }
  72. // [Fact]
  73. // [TestCaseSource(nameof(CreateFromPointsTestCases))]
  74. // public void CreateFromPoints(Vector2[] points, BoundingRectangle expectedBoundingRectangle)
  75. // {
  76. // var actualBoundingRectangle = BoundingRectangle.CreateFrom(points);
  77. // Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
  78. // }
  79. // public IEnumerable<TestCaseData> CreateFromTransformedTestCases
  80. // {
  81. // get
  82. // {
  83. // yield return
  84. // new TestCaseData(new BoundingRectangle(), Matrix3x2.Identity, new BoundingRectangle()).SetName(
  85. // "The bounding rectangle created from the empty bounding rectangle transformed by the identity matrix is the empty bounding rectangle.")
  86. // ;
  87. // yield return
  88. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Size2(20, 20)), Matrix3x2.CreateScale(2), new BoundingRectangle(new Vector2(0, 0), new Size2(40, 40))).SetName(
  89. // "The bounding rectangle created from a non-empty bounding rectangle transformed by a non-identity matrix is the expected bounding rectangle.")
  90. // ;
  91. // }
  92. // }
  93. // [Fact]
  94. // [TestCaseSource(nameof(CreateFromTransformedTestCases))]
  95. // public void CreateFromTransformed(BoundingRectangle boundingRectangle, Matrix3x2 transformMatrix,
  96. // BoundingRectangle expectedBoundingRectangle)
  97. // {
  98. // var actualBoundingRectangle = BoundingRectangle.Transform(boundingRectangle, ref transformMatrix);
  99. // Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
  100. // }
  101. // public IEnumerable<TestCaseData> UnionTestCases
  102. // {
  103. // get
  104. // {
  105. // yield return
  106. // new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), new BoundingRectangle()).SetName(
  107. // "The union of two empty bounding rectangles is the empty bounding rectangle.");
  108. // yield return
  109. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Size2(15, 15)),
  110. // new BoundingRectangle(new Vector2(20, 20), new Size2(40, 40)), new BoundingRectangle(new Vector2(20, 20), new Size2(40, 40)))
  111. // .SetName(
  112. // "The union of two non-empty bounding rectangles is the expected bounding rectangle.");
  113. // }
  114. // }
  115. // [Fact]
  116. // [TestCaseSource(nameof(UnionTestCases))]
  117. // public void Union(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, BoundingRectangle expectedBoundingRectangle)
  118. // {
  119. // Assert.Equal(expectedBoundingRectangle, boundingRectangle1.Union(boundingRectangle2));
  120. // Assert.Equal(expectedBoundingRectangle, BoundingRectangle.Union(boundingRectangle1, boundingRectangle2));
  121. // }
  122. // public IEnumerable<TestCaseData> IntersectionTestCases
  123. // {
  124. // get
  125. // {
  126. // yield return
  127. // new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), new BoundingRectangle()).SetName(
  128. // "The intersection of two empty bounding rectangles is the empty bounding box.");
  129. // yield return
  130. // new TestCaseData(new BoundingRectangle(new Vector2(-10, -10), new Size2(15, 15)),
  131. // new BoundingRectangle(new Vector2(20, 20), new Size2(40, 40)),
  132. // new BoundingRectangle(new Vector2(-7.5f, -7.5f), new Size2(12.5f, 12.5f))).SetName(
  133. // "The intersection of two overlapping non-empty bounding rectangles is the expected bounding rectangle.");
  134. // yield return
  135. // new TestCaseData(new BoundingRectangle(new Vector2(-30, -30), new Size2(15, 15)),
  136. // new BoundingRectangle(new Vector2(20, 20), new Size2(10, 10)),
  137. // BoundingRectangle.Empty).SetName(
  138. // "The intersection of two non-overlapping non-empty bounding rectangles is the empty bounding rectangle.");
  139. // }
  140. // }
  141. // [Fact]
  142. // [TestCaseSource(nameof(IntersectionTestCases))]
  143. // public void Intersection(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2,
  144. // BoundingRectangle? expectedBoundingRectangle)
  145. // {
  146. // Assert.Equal(expectedBoundingRectangle, boundingRectangle1.Intersection(boundingRectangle2));
  147. // Assert.Equal(expectedBoundingRectangle, BoundingRectangle.Intersection(boundingRectangle1, boundingRectangle2));
  148. // }
  149. // public IEnumerable<TestCaseData> IntersectsTestCases
  150. // {
  151. // get
  152. // {
  153. // yield return
  154. // new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), true).SetName(
  155. // "Two empty bounding rectangles intersect.");
  156. // yield return
  157. // new TestCaseData(new BoundingRectangle(new Vector2(-10, -10), new Size2(15, 15)),
  158. // new BoundingRectangle(new Vector2(20, 20), new Size2(40, 40)), true).SetName(
  159. // "Two overlapping non-empty bounding rectangles intersect.");
  160. // yield return
  161. // new TestCaseData(new BoundingRectangle(new Vector2(-40, -50), new Size2(15, 15)),
  162. // new BoundingRectangle(new Vector2(20, 20), new Size2(15, 15)), false).SetName(
  163. // "Two non-overlapping non-empty bounding rectangles do not intersect.");
  164. // }
  165. // }
  166. // [Fact]
  167. // [TestCaseSource(nameof(IntersectsTestCases))]
  168. // public void Intersects(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedToIntersect)
  169. // {
  170. // Assert.Equal(expectedToIntersect, boundingRectangle1.Intersects(boundingRectangle2));
  171. // Assert.Equal(expectedToIntersect, BoundingRectangle.Intersects(boundingRectangle1, boundingRectangle2));
  172. // }
  173. // public IEnumerable<TestCaseData> ContainsPointTestCases
  174. // {
  175. // get
  176. // {
  177. // yield return
  178. // new TestCaseData(new BoundingRectangle(), new Vector2(), true).SetName(
  179. // "The empty bounding rectangle contains the zero point.");
  180. // yield return
  181. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Size2(15, 15)), new Vector2(-15, -15), true)
  182. // .SetName(
  183. // "A non-empty bounding rectangle contains a point inside it.");
  184. // yield return
  185. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Size2(15, 15)), new Vector2(-16, 15), false)
  186. // .SetName(
  187. // "A non-empty bounding rectangle does not contain a point outside it.");
  188. // }
  189. // }
  190. // [Fact]
  191. // [TestCaseSource(nameof(ContainsPointTestCases))]
  192. // public void ContainsPoint(BoundingRectangle boundingRectangle, Vector2 point, bool expectedToContainPoint)
  193. // {
  194. // Assert.Equal(expectedToContainPoint, boundingRectangle.Contains(point));
  195. // Assert.Equal(expectedToContainPoint, BoundingRectangle.Contains(boundingRectangle, point));
  196. // }
  197. // public IEnumerable<TestCaseData> ClosestPointTestCases
  198. // {
  199. // get
  200. // {
  201. // yield return
  202. // new TestCaseData(new BoundingRectangle(), new Vector2(), new Vector2()).SetName(
  203. // "The closest point on the empty bounding rectangle to the zero point is the zero point.");
  204. // yield return
  205. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Vector2(50, 50)), new Vector2(25, 25),
  206. // new Vector2(25, 25)).SetName(
  207. // "The closest point on a non-empty bounding rectangle to a point which is inside the bounding rectangle is that point.")
  208. // ;
  209. // yield return
  210. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Vector2(50, 50)), new Vector2(400, 0),
  211. // new Vector2(50, 0)).SetName(
  212. // "The closest point on a non-empty bounding rectangle to a point which is outside the bounding rectangle is the expected point.")
  213. // ;
  214. // }
  215. // }
  216. // [Fact]
  217. // [TestCaseSource(nameof(ClosestPointTestCases))]
  218. // public void ClosestPoint(BoundingRectangle boundingRectangle, Vector2 point, Vector2 expectedClosestPoint)
  219. // {
  220. // var actualClosestPoint = boundingRectangle.ClosestPointTo(point);
  221. // Assert.Equal(expectedClosestPoint, actualClosestPoint);
  222. // }
  223. // public IEnumerable<TestCaseData> EqualityTestCases
  224. // {
  225. // get
  226. // {
  227. // yield return
  228. // new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), true).SetName(
  229. // "Empty bounding rectangles are equal.")
  230. // ;
  231. // yield return
  232. // new TestCaseData(
  233. // new BoundingRectangle(new Vector2(0, 0), new Size2(float.MaxValue, float.MinValue)),
  234. // new BoundingRectangle(new Vector2(0, 0),
  235. // new Vector2(float.MinValue, float.MaxValue)), false).SetName(
  236. // "Two different non-empty bounding rectangles are not equal.");
  237. // yield return
  238. // new TestCaseData(
  239. // new BoundingRectangle(new Vector2(0, 0), new Size2(float.MinValue, float.MaxValue)),
  240. // new BoundingRectangle(new Vector2(0, 0),
  241. // new Size2(float.MinValue, float.MaxValue)), true).SetName(
  242. // "Two identical non-empty bounding rectangles are equal.");
  243. // }
  244. // }
  245. // [Fact]
  246. // [TestCaseSource(nameof(EqualityTestCases))]
  247. // public void Equality(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedToBeEqual)
  248. // {
  249. // Assert.IsTrue(Equals(boundingRectangle1, boundingRectangle2) == expectedToBeEqual);
  250. // Assert.IsTrue(boundingRectangle1 == boundingRectangle2 == expectedToBeEqual);
  251. // Assert.IsFalse(boundingRectangle1 == boundingRectangle2 != expectedToBeEqual);
  252. // Assert.IsTrue(boundingRectangle1.Equals(boundingRectangle2) == expectedToBeEqual);
  253. // if (expectedToBeEqual)
  254. // Assert.Equal(boundingRectangle1.GetHashCode(), boundingRectangle2.GetHashCode());
  255. // }
  256. // public IEnumerable<TestCaseData> InequalityTestCases
  257. // {
  258. // get
  259. // {
  260. // yield return
  261. // new TestCaseData(new BoundingRectangle(), null, false).SetName(
  262. // "A bounding rectangle is not equal to a null object.");
  263. // yield return
  264. // new TestCaseData(new BoundingRectangle(), new object(), false).SetName(
  265. // "A bounding rectangle is not equal to an instantiated object.");
  266. // }
  267. // }
  268. // [Fact]
  269. // [TestCaseSource(nameof(InequalityTestCases))]
  270. // public void Inequality(BoundingRectangle boundingRectangle, object obj, bool expectedToBeEqual)
  271. // {
  272. // Assert.IsTrue(boundingRectangle.Equals(obj) == expectedToBeEqual);
  273. // }
  274. // public IEnumerable<TestCaseData> HashCodeTestCases
  275. // {
  276. // get
  277. // {
  278. // yield return
  279. // new TestCaseData(new BoundingRectangle(), new BoundingRectangle(), true).SetName(
  280. // "Two empty bounding rectangles have the same hash code.");
  281. // yield return
  282. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Size2(50, 50)),
  283. // new BoundingRectangle(new Vector2(0, 0), new Size2(50, 50)), true).SetName(
  284. // "Two indentical non-empty bounding rectangles have the same hash code.");
  285. // yield return
  286. // new TestCaseData(new BoundingRectangle(new Vector2(0, 0), new Size2(50, 50)),
  287. // new BoundingRectangle(new Vector2(50, 50), new Size2(50, 50)), false).SetName(
  288. // "Two different non-empty bounding rectangles do not have the same hash code.");
  289. // }
  290. // }
  291. // [Fact]
  292. // [TestCaseSource(nameof(HashCodeTestCases))]
  293. // public void HashCode(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedThatHashCodesAreEqual)
  294. // {
  295. // var hashCode1 = boundingRectangle1.GetHashCode();
  296. // var hashCode2 = boundingRectangle2.GetHashCode();
  297. // if (expectedThatHashCodesAreEqual)
  298. // Assert.Equal(hashCode1, hashCode2);
  299. // else
  300. // Assert.AreNotEqual(hashCode1, hashCode2);
  301. // }
  302. // public IEnumerable<TestCaseData> ToRectangleTestCases
  303. // {
  304. // get
  305. // {
  306. // yield return
  307. // new TestCaseData(new BoundingRectangle(), new Rectangle()).SetName(
  308. // "The empty bounding rectangle point converted to a rectangle is the empty rectangle.");
  309. // yield return
  310. // new TestCaseData(new BoundingRectangle(new Vector2(25, 25), new Size2(25, 25)),
  311. // new Rectangle(0, 0, 50, 50)).SetName(
  312. // "A non-empty bounding rectangle converted to a rectangle is the expected rectangle.");
  313. // }
  314. // }
  315. // [Fact]
  316. // [TestCaseSource(nameof(ToRectangleTestCases))]
  317. // public void ToRectangle(BoundingRectangle boundingRectangle, Rectangle expectedRectangle)
  318. // {
  319. // var actualRectangle = (Rectangle)boundingRectangle;
  320. // Assert.Equal(expectedRectangle, actualRectangle);
  321. // }
  322. // public IEnumerable<TestCaseData> FromRectangleTestCases
  323. // {
  324. // get
  325. // {
  326. // yield return
  327. // new TestCaseData(new Rectangle(), new BoundingRectangle()).SetName(
  328. // "The empty rectangle converted to a bounding rectangle is the empty bounding rectangle.");
  329. // yield return
  330. // new TestCaseData(new Rectangle(0, 0, 50, 50),
  331. // new BoundingRectangle(new Vector2(25, 25), new Size2(25, 25))).SetName(
  332. // "A non-empty rectangle converted to a bounding rectangle is the expected bounding rectangle.");
  333. // }
  334. // }
  335. // [Fact]
  336. // [TestCaseSource(nameof(FromRectangleTestCases))]
  337. // public void FromRectangle(Rectangle rectangle, BoundingRectangle expectedBoundingRectangle)
  338. // {
  339. // var actualBoundingRectangle = (BoundingRectangle)rectangle;
  340. // Assert.Equal(expectedBoundingRectangle, actualBoundingRectangle);
  341. // }
  342. // public IEnumerable<TestCaseData> StringCases
  343. // {
  344. // get
  345. // {
  346. // yield return
  347. // new TestCaseData(new BoundingRectangle(),
  348. // string.Format(CultureInfo.CurrentCulture, "Centre: {0}, Radii: {1}", new Vector2(),
  349. // new Vector2())).SetName(
  350. // "The empty bounding rectangle has the expected string representation using the current culture.");
  351. // yield return new TestCaseData(new BoundingRectangle(new Vector2(5.1f, -5.123f), new Size2(5.4f, -5.4123f)),
  352. // string.Format(CultureInfo.CurrentCulture, "Centre: {0}, Radii: {1}", new Vector2(5.1f, -5.123f),
  353. // new Vector2(5.4f, -5.4123f))).SetName(
  354. // "A non-empty bounding rectangle has the expected string representation using the current culture.");
  355. // }
  356. // }
  357. // [Fact]
  358. // [TestCaseSource(nameof(StringCases))]
  359. // public void String(BoundingRectangle boundingRectangle, string expectedString)
  360. // {
  361. // var actualString = boundingRectangle.ToString();
  362. // Assert.Equal(expectedString, actualString);
  363. // }
  364. // }
  365. //}