001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Denis M. Kishenko
019: * @version $Revision$
020: */package java.awt.geom;
021:
022: import java.awt.Rectangle;
023:
024: import junit.framework.TestCase;
025:
026: public class Rectangle2DFloatTest extends TestCase {
027:
028: Rectangle2D.Float r;
029:
030: public Rectangle2DFloatTest(String name) {
031: super (name);
032: }
033:
034: @Override
035: protected void setUp() throws Exception {
036: super .setUp();
037: r = new Rectangle2D.Float(1, 2, 3, 4);
038: }
039:
040: @Override
041: protected void tearDown() throws Exception {
042: r = null;
043: super .tearDown();
044: }
045:
046: public void testCreate() {
047: assertEquals(new Rectangle2D.Double(0, 0, 0, 0),
048: new Rectangle2D.Double());
049: }
050:
051: public void testGetX() {
052: assertEquals(1.0f, r.getX(), 0.0f);
053: }
054:
055: public void testGetY() {
056: assertEquals(2.0f, r.getY(), 0.0f);
057: }
058:
059: public void testGetWidth() {
060: assertEquals(3.0f, r.getWidth(), 0.0f);
061: }
062:
063: public void testGetHeight() {
064: assertEquals(4.0f, r.getHeight(), 0.0f);
065: }
066:
067: public void testIsEmpty() {
068: assertFalse(r.isEmpty());
069: assertTrue(new Rectangle2D.Float(1, 2, -1, 1).isEmpty());
070: assertTrue(new Rectangle2D.Float(3, 4, 1, -1).isEmpty());
071: assertTrue(new Rectangle2D.Float(3, 4, 1, 0).isEmpty());
072: assertTrue(new Rectangle2D.Float(5, 6, -1, -1).isEmpty());
073: }
074:
075: public void testSetRect1() {
076: r.setRect(5.0, 6.0, 7.0, 8.0);
077: assertEquals(new Rectangle2D.Float(5, 6, 7, 8), r);
078: }
079:
080: public void testSetRect2() {
081: r.setRect(5.0f, 6.0f, 7.0f, 8.0f);
082: assertEquals(new Rectangle2D.Float(5, 6, 7, 8), r);
083: }
084:
085: public void testSetRect3() {
086: r.setRect(new Rectangle(5, 6, 7, 8));
087: assertEquals(new Rectangle2D.Float(5, 6, 7, 8), r);
088: }
089:
090: public void testOutcode() {
091: assertEquals(Rectangle2D.OUT_LEFT | Rectangle2D.OUT_TOP, r
092: .outcode(0, 0));
093: assertEquals(Rectangle2D.OUT_TOP, r.outcode(2, 0));
094: assertEquals(Rectangle2D.OUT_RIGHT | Rectangle2D.OUT_TOP, r
095: .outcode(5, 0));
096: assertEquals(Rectangle2D.OUT_RIGHT, r.outcode(5, 3));
097: assertEquals(Rectangle2D.OUT_RIGHT | Rectangle2D.OUT_BOTTOM, r
098: .outcode(5, 7));
099: assertEquals(Rectangle2D.OUT_BOTTOM, r.outcode(2, 7));
100: assertEquals(Rectangle2D.OUT_LEFT | Rectangle2D.OUT_BOTTOM, r
101: .outcode(0, 7));
102: assertEquals(Rectangle2D.OUT_LEFT, r.outcode(0, 3));
103: assertEquals(0, r.outcode(2, 3));
104: }
105:
106: public void testGetBounds2D() {
107: assertEquals(new Rectangle2D.Float(1, 2, 3, 4), r.getBounds2D());
108: }
109:
110: public void testToString() {
111: assertEquals(
112: "java.awt.geom.Rectangle2D$Float[x=1.0,y=2.0,width=3.0,height=4.0]",
113: r.toString());
114: }
115:
116: public void testCreateIntersection() {
117: assertEquals(new Rectangle2D.Float(1, 2, -1, -2), r
118: .createIntersection(new Rectangle2D.Float())); // Empty
119: assertEquals(new Rectangle2D.Double(1, 2, 3, 4), r
120: .createIntersection(new Rectangle2D.Double(1, 2, 3, 4))); // The same
121: assertEquals(new Rectangle2D.Float(2, 3, 1, 2), r
122: .createIntersection(new Rectangle2D.Float(2, 3, 1, 2))); // Inside
123: assertEquals(new Rectangle2D.Double(5, 7, -1, -1), r
124: .createIntersection(new Rectangle2D.Double(5, 7, 1, 2))); // Outside
125: assertEquals(new Rectangle2D.Float(2, 3, 2, 3), r
126: .createIntersection(new Rectangle2D.Float(2, 3, 5, 6))); // Intersect
127: assertEquals(new Rectangle2D.Double(1, 2, 3, 4), r
128: .createIntersection(new Rectangle2D.Double(0, 0, 5, 6))); // Cover
129: }
130:
131: public void testCreateUnion() {
132: // assertEquals(r.createUnion(new Rectangle2D.Double()), new Rectangle2D.Double(1, 2, 3, 4)); // Empty
133: assertEquals(new Rectangle2D.Float(1, 2, 3, 4), r
134: .createUnion(new Rectangle2D.Float(1, 2, 3, 4))); // The same
135: assertEquals(new Rectangle2D.Double(1, 2, 3, 4), r
136: .createUnion(new Rectangle2D.Double(2, 3, 1, 2))); // Inside
137: assertEquals(new Rectangle2D.Float(1, 2, 5, 7), r
138: .createUnion(new Rectangle2D.Float(5, 7, 1, 2))); // Outside
139: assertEquals(new Rectangle2D.Double(1, 2, 6, 7), r
140: .createUnion(new Rectangle2D.Double(2, 3, 5, 6))); // Intersect
141: assertEquals(new Rectangle2D.Float(0, 0, 5, 6), r
142: .createUnion(new Rectangle2D.Float(0, 0, 5, 6))); // Cover
143: }
144:
145: public static void main(String[] args) {
146: junit.textui.TestRunner.run(Rectangle2DFloatTest.class);
147: }
148:
149: }
|