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