CircleFTests.cs 18 KB

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