CollisionTest.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using MineCase.Algorithm;
  5. using MineCase.Graphics;
  6. using Xunit;
  7. namespace MineCase.UnitTest
  8. {
  9. public class CollisionTest
  10. {
  11. [Fact]
  12. public void TestCollsion()
  13. {
  14. var shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 2f));
  15. var shape2 = new Cuboid(new Point3d(0.9f, 0.9f, 1f), new Size(1f, 1f, 1f));
  16. var result = Collision.IsCollided(shape1, shape2);
  17. Assert.True(result);
  18. shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 1f));
  19. shape2 = new Cuboid(new Point3d(-0.5f, 0.3f, 0.5f), new Size(3f, 0.1f, 0.1f));
  20. result = Collision.IsCollided(shape1, shape2);
  21. Assert.True(result);
  22. }
  23. [Fact]
  24. public void TestNotCollsion()
  25. {
  26. var shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 2f));
  27. var shape2 = new Cuboid(new Point3d(2f, 2f, 1f), new Size(1f, 1f, 1f));
  28. var result = Collision.IsCollided(shape1, shape2);
  29. Assert.False(result);
  30. shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 1f));
  31. shape2 = new Cuboid(new Point3d(0f, 0f, 2f), new Size(1f, 1f, 1f));
  32. result = Collision.IsCollided(shape1, shape2);
  33. Assert.False(result);
  34. }
  35. [Fact]
  36. public void TestBoundaryCollsion()
  37. {
  38. var shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 2f));
  39. var shape2 = new Cuboid(new Point3d(1f, 0f, 0f), new Size(1f, 1f, 1f));
  40. var result = Collision.IsCollided(shape1, shape2);
  41. Assert.True(result);
  42. shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 1f));
  43. shape2 = new Cuboid(new Point3d(0f, 0f, 1f), new Size(1f, 1f, 1f));
  44. result = Collision.IsCollided(shape1, shape2);
  45. Assert.True(result);
  46. shape1 = new Cuboid(new Point3d(0f, 0f, 0f), new Size(1f, 1f, 1f));
  47. shape2 = new Cuboid(new Point3d(1f, 1f, 1f), new Size(1f, 1f, 1f));
  48. result = Collision.IsCollided(shape1, shape2);
  49. Assert.True(result);
  50. }
  51. }
  52. }