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.Point;
023:
024: import junit.framework.TestCase;
025:
026: public class Point2DTest extends TestCase {
027:
028: final static double DELTA = 0.001;
029:
030: Point p;
031:
032: public Point2DTest(String name) {
033: super (name);
034: }
035:
036: @Override
037: protected void setUp() throws Exception {
038: super .setUp();
039: p = new Point(1, 2);
040: }
041:
042: @Override
043: protected void tearDown() throws Exception {
044: p = null;
045: super .tearDown();
046: }
047:
048: public void testSetLocation() {
049: p.setLocation(new Point(3, 4));
050: assertEquals(new Point(3, 4), p);
051: }
052:
053: public void testClone() {
054: assertEquals(p, p.clone());
055: }
056:
057: public void testEquals() {
058: assertTrue(p.equals(p));
059: assertTrue(p.equals(new Point(1, 2)));
060: assertFalse(p.equals(new Point(1, 3)));
061: assertFalse(p.equals(new Point(0, 2)));
062: assertFalse(p.equals(new Point(0, 3)));
063: assertFalse(p.equals(new Point2D.Double(0, 3)));
064: }
065:
066: public void testHashCode() {
067: assertTrue(p.hashCode() == new Point(1, 2).hashCode());
068: assertTrue(p.hashCode() != new Point(1, 3).hashCode());
069: assertTrue(p.hashCode() != new Point(0, 2).hashCode());
070: assertTrue(p.hashCode() != new Point(0, 0).hashCode());
071: }
072:
073: public void testDistanceSq1() {
074: assertEquals(8.0, Point2D.distanceSq(1, 2, 3, 4), 0.0);
075: assertEquals(0.0, Point2D.distanceSq(1, 2, 1, 2), 0.0);
076: }
077:
078: public void testDistanceSq2() {
079: assertEquals(8.0, p.distanceSq(3, 4), 0.0);
080: assertEquals(0.0, p.distanceSq(1, 2), 0.0);
081: }
082:
083: public void testDistanceSq3() {
084: assertEquals(8.0, p.distanceSq(new Point(3, 4)), 0.0);
085: assertEquals(0.0, p.distanceSq(new Point(1, 2)), 0.0);
086: }
087:
088: public void testDistance1() {
089: assertEquals(Math.sqrt(8.0), Point2D.distance(1, 2, 3, 4),
090: DELTA);
091: assertEquals(0.0, Point2D.distance(1, 2, 1, 2), DELTA);
092: }
093:
094: public void testDistance2() {
095: assertEquals(Math.sqrt(8.0), p.distance(3, 4), DELTA);
096: assertEquals(0.0, p.distance(1, 2), DELTA);
097: }
098:
099: public void testDistance3() {
100: assertEquals(Math.sqrt(8.0), p.distance(new Point(3, 4)), DELTA);
101: assertEquals(0.0, p.distance(new Point(1, 2)), DELTA);
102: }
103:
104: public static void main(String[] args) {
105: junit.textui.TestRunner.run(Point2DTest.class);
106: }
107:
108: }
|