PointTests.cs
上传用户:sex100000
上传日期:2013-11-09
资源大小:1377k
文件大小:3k
源码类别:

GIS编程

开发平台:

C#

  1. using System;
  2. using NUnit.Framework;
  3. using SharpMap.Geometries;
  4. namespace UnitTests.Geometries
  5. {
  6. [TestFixture]
  7. public class PointTests
  8. {
  9. [Test]
  10. public void Point()
  11. {
  12. //Do various Point method calls to cover the point class with sufficient testing
  13. Point p0 = new Point();
  14. Point p1 = new Point(0,0);
  15. Point p2 = new Point(450, 120);
  16. Assert.IsTrue(p0.IsEmpty());
  17. Assert.IsFalse(p1.IsEmpty());
  18. Assert.AreNotEqual(p0, p1);
  19. Assert.AreEqual(450, p2.X);
  20. Assert.AreEqual(120, p2.Y);
  21. Assert.AreNotSame(p2.Clone(), p2);
  22. p0 = p2.Clone();
  23. p0.X += 100; p0.Y = 150;
  24. p0[0] += p0[1];
  25. Assert.AreEqual(new Point(700, 150),p0);
  26. Assert.AreEqual(p2, p2.GetBoundingBox().Min);
  27. Assert.AreEqual(p2, p2.GetBoundingBox().Max);
  28. Assert.IsTrue(p2.IsSimple());
  29. Assert.IsFalse(p2.IsEmpty());
  30. Assert.AreEqual(2, p2.NumOrdinates);
  31. Assert.AreEqual(new Point(400, 100), p2 + new Point(-50, -20));
  32. Assert.AreEqual(new Point(500, 100), p2 - new Point(-50, 20));
  33. Assert.AreEqual(new Point(900, 240), p2 * 2);
  34. Assert.AreEqual(0, p2.Dimension);
  35. Assert.AreEqual(450, p2[0]);
  36. Assert.AreEqual(120, p2[1]);
  37. Assert.IsNull(p2.Boundary());
  38. Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.IsEmpty().GetHashCode(), p2.GetHashCode());
  39. Assert.Greater(p2.CompareTo(p1), 0);
  40. Assert.Less(p1.CompareTo(p2), 0);
  41. Assert.AreEqual(p2.CompareTo(new Point(450,120)), 0);
  42. }
  43. [Test]
  44. public void Point3D()
  45. {
  46. //Do various Point method calls to cover the point class with sufficient testing
  47. Point3D p0 = new Point3D();
  48. Point p = new Point(23,21);
  49. Point3D p1 = new Point3D(450, 120, 34);
  50. Point3D p2 = new Point3D(p, 94);
  51. Assert.IsTrue(p0.IsEmpty());
  52. Assert.IsFalse(p1.IsEmpty());
  53. Assert.IsFalse(p2.IsEmpty());
  54. Assert.AreNotEqual(p, p2);
  55. Assert.AreEqual(94, p2.Z);
  56. Assert.AreNotSame(p1.Clone(), p1);
  57. p0 = p1.Clone();
  58. p0.X += 100; p0.Y = 150; p0.Z += 499;
  59. p0[2] += p0[2];
  60. Assert.AreEqual(new Point3D(550, 150, 1066), p0);
  61. Assert.AreEqual(p2.AsPoint(), p2.GetBoundingBox().Min);
  62. Assert.AreEqual(p2.AsPoint(), p2.GetBoundingBox().Max);
  63. Assert.AreEqual(3, p2.NumOrdinates);
  64. Assert.AreEqual(new Point3D(-27, 1, 123), p2 + new Point3D(-50, -20, 29));
  65. Assert.AreEqual(new Point(73, 1), p2 - new Point(-50, 20));
  66. Assert.AreEqual(new Point3D(46, 42, 188), p2 * 2);
  67. Assert.AreEqual(0, p2.Dimension);
  68. Assert.AreEqual(23, p2[0]);
  69. Assert.AreEqual(21, p2[1]);
  70. Assert.AreEqual(94, p2[2]);
  71. Assert.IsNull(p2.Boundary());
  72. Assert.AreEqual(p2.X.GetHashCode() ^ p2.Y.GetHashCode() ^ p2.Z.GetHashCode() ^ p2.IsEmpty().GetHashCode(), p2.GetHashCode());
  73. Assert.Less(p2.CompareTo(p1), 0);
  74. Assert.Greater(p1.CompareTo(p2), 0);
  75. Assert.AreEqual(0, p2.CompareTo(new Point3D(23, 21, 94)));
  76. Assert.AreEqual(0, p2.CompareTo(new Point(23, 21)));
  77. }
  78. }
  79. }