Ray2DTests.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 Ray2Tests
  9. // {
  10. // public IEnumerable<TestCaseData> ConstructorTestCases
  11. // {
  12. // get
  13. // {
  14. // yield return
  15. // new TestCaseData(new Vector2(), new Vector2()).SetName(
  16. // "The degenerate ray has the expected position and direction.");
  17. // yield return
  18. // new TestCaseData(new Vector2(5, 5), new Vector2(15, 15)).SetName(
  19. // "A non-degenerate ray has the expected position and direction.");
  20. // }
  21. // }
  22. // [Fact]
  23. // [TestCaseSource(nameof(ConstructorTestCases))]
  24. // public void Constructor(Vector2 position, Vector2 direction)
  25. // {
  26. // var ray = new Ray2(position, direction);
  27. // Assert.Equal(position, ray.Position);
  28. // Assert.Equal(direction, ray.Direction);
  29. // }
  30. // public IEnumerable<TestCaseData> PositionDirectionTestCases
  31. // {
  32. // get
  33. // {
  34. // yield return
  35. // new TestCaseData(new Ray2(), new Vector2(), new Vector2()).SetName(
  36. // "The degenerate ray has the expected position and direction.");
  37. // yield return
  38. // new TestCaseData(new Ray2(new Vector2(5, 5), new Vector2(15, 15)), new Vector2(5, 5),
  39. // new Vector2(15, 15)).SetName
  40. // (
  41. // "A non-degenerate ray has the expected position and direction.");
  42. // }
  43. // }
  44. // [Fact]
  45. // [TestCaseSource(nameof(PositionDirectionTestCases))]
  46. // public void PositionDirection(Ray2 ray, Vector2 expectedPosition, Vector2 expecetedDirection)
  47. // {
  48. // Assert.Equal(expectedPosition, ray.Position);
  49. // Assert.Equal(expecetedDirection, ray.Direction);
  50. // ray.Position.X = 10;
  51. // ray.Position.Y = 10;
  52. // Assert.Equal(new Vector2(10, 10), ray.Position);
  53. // ray.Direction.X = -10.123f;
  54. // ray.Direction.Y = 10.123f;
  55. // Assert.Equal(new Vector2(-10.123f, 10.123f), ray.Direction);
  56. // }
  57. // public IEnumerable<TestCaseData> IntersectsBoundingRectangleTestCases
  58. // {
  59. // get
  60. // {
  61. // yield return
  62. // new TestCaseData(new Ray2(), new BoundingRectangle(), true, Vector2.Zero, Vector2.Zero).SetName(
  63. // "The degenerate ray intersects the empty bounding box.");
  64. // yield return
  65. // new TestCaseData(new Ray2(new Vector2(-75, -75), new Vector2(75, -75)),
  66. // new BoundingRectangle(new Vector2(), new Size2(50, 50)), false, Vector2.NaN, Vector2.NaN).SetName(
  67. // "A non-degenerate ray that does not cross a non-empty bounding box does not intersect the bounding box.");
  68. // yield return
  69. // new TestCaseData(new Ray2(new Vector2(0, 0), new Vector2(25, 0)), new BoundingRectangle(new Vector2(), new Size2(50, 50)),
  70. // true, new Vector2(0, 0), new Vector2(50, 0)).SetName(
  71. // "A non-degenerate ray starting from inside a non-empty bounding box intersects the bounding box.");
  72. // yield return
  73. // new TestCaseData(new Ray2(new Vector2(-100, 0), new Vector2(100, 0)),
  74. // new BoundingRectangle(new Vector2(), new Size2(50, 50)),
  75. // true, new Vector2(-50, 0), new Vector2(50, 0)).SetName(
  76. // "A non-degenerate ray crossing a non-empty bounding box intersects the bounding box.");
  77. // }
  78. // }
  79. // [Fact]
  80. // [TestCaseSource(nameof(IntersectsBoundingRectangleTestCases))]
  81. // public void IntersectsBoundingRectangle(Ray2 ray, BoundingRectangle boundingRectangle, bool expectedResult,
  82. // Vector2 firstExpectedIntersectionPoint, Vector2 secondExpectedIntersectionPoint)
  83. // {
  84. // float rayNearDistance, rayFarDistance;
  85. // var actualResult = ray.Intersects(boundingRectangle, out rayNearDistance, out rayFarDistance);
  86. // Assert.Equal(expectedResult, actualResult);
  87. // if (actualResult)
  88. // {
  89. // var firstActualIntersectionPoint = ray.Position + ray.Direction * rayNearDistance;
  90. // Assert.Equal(firstExpectedIntersectionPoint, firstActualIntersectionPoint);
  91. // var secondActualIntersectionPoint = ray.Position + ray.Direction * rayFarDistance;
  92. // Assert.Equal(secondExpectedIntersectionPoint, secondActualIntersectionPoint);
  93. // }
  94. // else
  95. // {
  96. // Assert.IsTrue(float.IsNaN(rayNearDistance));
  97. // Assert.IsTrue(float.IsNaN(rayFarDistance));
  98. // }
  99. // }
  100. // public IEnumerable<TestCaseData> EqualityTestCases
  101. // {
  102. // get
  103. // {
  104. // yield return
  105. // new TestCaseData(new Ray2(), new Ray2(), true).SetName("Two degenerate rays are equal.");
  106. // yield return
  107. // new TestCaseData(new Ray2(new Vector2(float.MinValue, float.MaxValue),
  108. // new Vector2(float.MaxValue, float.MinValue)), new Ray2(new Vector2(float.MaxValue, float.MinValue),
  109. // new Vector2(float.MaxValue, float.MinValue)), false).SetName(
  110. // "Two different non-degenerate rays are not equal.");
  111. // yield return
  112. // new TestCaseData(
  113. // new Ray2(new Vector2(float.MinValue, float.MaxValue),
  114. // new Vector2(float.MinValue, float.MaxValue)), new Ray2(new Vector2(float.MinValue, float.MaxValue),
  115. // new Vector2(float.MinValue, float.MaxValue)), true)
  116. // .SetName(
  117. // "Two identical non-degenerate rays are equal.");
  118. // }
  119. // }
  120. // [Fact]
  121. // [TestCaseSource(nameof(EqualityTestCases))]
  122. // public void Equality(Ray2 ray1, Ray2 ray2, bool expectedToBeEqual)
  123. // {
  124. // Assert.IsTrue(Equals(ray1, ray2) == expectedToBeEqual);
  125. // Assert.IsTrue(ray1 == ray2 == expectedToBeEqual);
  126. // Assert.IsFalse(ray1 == ray2 != expectedToBeEqual);
  127. // Assert.IsTrue(ray1.Equals(ray2) == expectedToBeEqual);
  128. // if (expectedToBeEqual)
  129. // Assert.Equal(ray1.GetHashCode(), ray2.GetHashCode());
  130. // }
  131. // public IEnumerable<TestCaseData> InequalityTestCases
  132. // {
  133. // get
  134. // {
  135. // yield return
  136. // new TestCaseData(new Ray2(), null, false).SetName("A ray is not equal to a null object.");
  137. // yield return
  138. // new TestCaseData(new Ray2(), new object(), false).SetName(
  139. // "A ray is not equal to an instantiated object.");
  140. // }
  141. // }
  142. // [Fact]
  143. // [TestCaseSource(nameof(InequalityTestCases))]
  144. // public void Inequality(Ray2 ray, object obj, bool expectedToBeEqual)
  145. // {
  146. // Assert.IsTrue(ray.Equals(obj) == expectedToBeEqual);
  147. // }
  148. // public IEnumerable<TestCaseData> HashCodeTestCases
  149. // {
  150. // get
  151. // {
  152. // yield return
  153. // new TestCaseData(new Ray2(), new Ray2(), true).SetName(
  154. // "Two degenerate rays have the same hash code.");
  155. // yield return
  156. // new TestCaseData(new Ray2(new Vector2(50, 50), new Vector2(50, 50)),
  157. // new Ray2(new Vector2(50, 50), new Vector2(50, 50)), true).SetName(
  158. // "Two indentical non-zero points have the same hash code.");
  159. // yield return
  160. // new TestCaseData(new Ray2(new Vector2(0, 0), new Vector2(50, 50)),
  161. // new Ray2(new Vector2(50, 50), new Vector2(50, 50)), false).SetName(
  162. // "Two different non-zero points do not have the same hash code.");
  163. // }
  164. // }
  165. // [Fact]
  166. // [TestCaseSource(nameof(HashCodeTestCases))]
  167. // public void HashCode(Ray2 ray1, Ray2 ray2, bool expectedThatHashCodesAreEqual)
  168. // {
  169. // var hashCode1 = ray1.GetHashCode();
  170. // var hashCode2 = ray2.GetHashCode();
  171. // if (expectedThatHashCodesAreEqual)
  172. // Assert.Equal(hashCode1, hashCode2);
  173. // else
  174. // Assert.AreNotEqual(hashCode1, hashCode2);
  175. // }
  176. // public IEnumerable<TestCaseData> StringCases
  177. // {
  178. // get
  179. // {
  180. // yield return
  181. // new TestCaseData(new Ray2(),
  182. // string.Format(CultureInfo.CurrentCulture, "Position: {0}, Direction: {1}", new Vector2(),
  183. // new Vector2())).SetName(
  184. // "The degenerate ray has the expected string representation using the current culture.");
  185. // yield return new TestCaseData(new Ray2(new Vector2(5.1f, -5.123f), new Vector2(0, 1)),
  186. // string.Format(CultureInfo.CurrentCulture, "Position: {0}, Direction: {1}", new Vector2(5.1f, -5.123f),
  187. // new Vector2(0, 1))).SetName(
  188. // "A non-degenerate ray has the expected string representation using the current culture.");
  189. // }
  190. // }
  191. // [Fact]
  192. // [TestCaseSource(nameof(StringCases))]
  193. // public void String(Ray2 ray, string expectedString)
  194. // {
  195. // var actualString = ray.ToString();
  196. // Assert.Equal(expectedString, actualString);
  197. // }
  198. // }
  199. //}