PointTest.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package org.opencv.test.core;
  2. import org.opencv.core.Point;
  3. import org.opencv.core.Rect;
  4. import org.opencv.test.OpenCVTestCase;
  5. public class PointTest extends OpenCVTestCase {
  6. private Point p1;
  7. private Point p2;
  8. @Override
  9. protected void setUp() throws Exception {
  10. super.setUp();
  11. p1 = new Point(2, 2);
  12. p2 = new Point(1, 1);
  13. }
  14. public void testClone() {
  15. Point truth = new Point(1, 1);
  16. Point dstPoint = truth.clone();
  17. assertEquals(truth, dstPoint);
  18. }
  19. public void testDot() {
  20. double result = p1.dot(p2);
  21. assertEquals(4.0, result);
  22. }
  23. public void testEqualsObject() {
  24. boolean flag = p1.equals(p1);
  25. assertTrue(flag);
  26. flag = p1.equals(p2);
  27. assertFalse(flag);
  28. }
  29. public void testHashCode() {
  30. assertEquals(p1.hashCode(), p1.hashCode());
  31. }
  32. public void testInside() {
  33. Rect rect = new Rect(0, 0, 5, 3);
  34. assertTrue(p1.inside(rect));
  35. Point p2 = new Point(3, 3);
  36. assertFalse(p2.inside(rect));
  37. }
  38. public void testPoint() {
  39. Point p = new Point();
  40. assertNotNull(p);
  41. assertEquals(0.0, p.x);
  42. assertEquals(0.0, p.y);
  43. }
  44. public void testPointDoubleArray() {
  45. double[] vals = { 2, 4 };
  46. Point p = new Point(vals);
  47. assertEquals(2.0, p.x);
  48. assertEquals(4.0, p.y);
  49. }
  50. public void testPointDoubleDouble() {
  51. p1 = new Point(7, 5);
  52. assertNotNull(p1);
  53. assertEquals(7.0, p1.x);
  54. assertEquals(5.0, p1.y);
  55. }
  56. public void testSet() {
  57. double[] vals1 = {};
  58. p1.set(vals1);
  59. assertEquals(0.0, p1.x);
  60. assertEquals(0.0, p1.y);
  61. double[] vals2 = { 6, 10 };
  62. p2.set(vals2);
  63. assertEquals(6.0, p2.x);
  64. assertEquals(10.0, p2.y);
  65. }
  66. public void testToString() {
  67. String actual = p1.toString();
  68. String expected = "{2.0, 2.0}";
  69. assertEquals(expected, actual);
  70. }
  71. }