RectTest.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package org.opencv.test.core;
  2. import org.opencv.core.Point;
  3. import org.opencv.core.Rect;
  4. import org.opencv.core.Size;
  5. import org.opencv.test.OpenCVTestCase;
  6. public class RectTest extends OpenCVTestCase {
  7. private Rect r;
  8. private Rect rect;
  9. @Override
  10. protected void setUp() throws Exception {
  11. super.setUp();
  12. r = new Rect();
  13. rect = new Rect(0, 0, 10, 10);
  14. }
  15. public void testArea() {
  16. double area;
  17. area = rect.area();
  18. assertEquals(100.0, area);
  19. }
  20. public void testBr() {
  21. Point p_br = new Point();
  22. p_br = rect.br();
  23. Point truth = new Point(10, 10);
  24. assertEquals(truth, p_br);
  25. }
  26. public void testClone() {
  27. r = rect.clone();
  28. assertEquals(rect, r);
  29. }
  30. public void testContains() {
  31. Rect rect = new Rect(0, 0, 10, 10);
  32. Point p_inner = new Point(5, 5);
  33. Point p_outer = new Point(5, 55);
  34. Point p_bl = new Point(0, 0);
  35. Point p_br = new Point(10, 0);
  36. Point p_tl = new Point(0, 10);
  37. Point p_tr = new Point(10, 10);
  38. assertTrue(rect.contains(p_inner));
  39. assertTrue(rect.contains(p_bl));
  40. assertFalse(rect.contains(p_outer));
  41. assertFalse(rect.contains(p_br));
  42. assertFalse(rect.contains(p_tl));
  43. assertFalse(rect.contains(p_tr));
  44. }
  45. public void testEqualsObject() {
  46. boolean flag;
  47. flag = rect.equals(r);
  48. assertFalse(flag);
  49. r = rect.clone();
  50. flag = rect.equals(r);
  51. assertTrue(flag);
  52. }
  53. public void testHashCode() {
  54. assertEquals(rect.hashCode(), rect.hashCode());
  55. }
  56. public void testRect() {
  57. r = new Rect();
  58. assertEquals(0, r.x);
  59. assertEquals(0, r.y);
  60. assertEquals(0, r.width);
  61. assertEquals(0, r.height);
  62. }
  63. public void testRectDoubleArray() {
  64. double[] vals = { 1, 3, 5, 2 };
  65. r = new Rect(vals);
  66. assertEquals(1, r.x);
  67. assertEquals(3, r.y);
  68. assertEquals(5, r.width);
  69. assertEquals(2, r.height);
  70. }
  71. public void testRectIntIntIntInt() {
  72. r = new Rect(1, 3, 5, 2);
  73. assertNotNull(rect);
  74. assertEquals(0, rect.x);
  75. assertEquals(0, rect.y);
  76. assertEquals(10, rect.width);
  77. assertEquals(10, rect.height);
  78. }
  79. public void testRectPointPoint() {
  80. Point p1 = new Point(4, 4);
  81. Point p2 = new Point(2, 3);
  82. r = new Rect(p1, p2);
  83. assertNotNull(r);
  84. assertEquals(2, r.x);
  85. assertEquals(3, r.y);
  86. assertEquals(2, r.width);
  87. assertEquals(1, r.height);
  88. }
  89. public void testRectPointSize() {
  90. Point p1 = new Point(4, 4);
  91. Size sz = new Size(3, 1);
  92. r = new Rect(p1, sz);
  93. assertEquals(4, r.x);
  94. assertEquals(4, r.y);
  95. assertEquals(3, r.width);
  96. assertEquals(1, r.height);
  97. }
  98. public void testSet() {
  99. double[] vals1 = {};
  100. Rect r1 = new Rect(vals1);
  101. assertEquals(0, r1.x);
  102. assertEquals(0, r1.y);
  103. assertEquals(0, r1.width);
  104. assertEquals(0, r1.height);
  105. double[] vals2 = { 2, 2, 10, 5 };
  106. r = new Rect(vals2);
  107. assertEquals(2, r.x);
  108. assertEquals(2, r.y);
  109. assertEquals(10, r.width);
  110. assertEquals(5, r.height);
  111. }
  112. public void testSize() {
  113. Size s1 = new Size(0, 0);
  114. assertEquals(s1, r.size());
  115. Size s2 = new Size(10, 10);
  116. assertEquals(s2, rect.size());
  117. }
  118. public void testTl() {
  119. Point p_tl = new Point();
  120. p_tl = rect.tl();
  121. Point truth = new Point(0, 0);
  122. assertEquals(truth, p_tl);
  123. }
  124. public void testToString() {
  125. String actual = rect.toString();
  126. String expected = "{0, 0, 10x10}";
  127. assertEquals(expected, actual);
  128. }
  129. }