This is the mail archive of the
mauve-patches@sources.redhat.com
mailing list for the Mauve project.
java.awt.geom.Rectangle2D
- From: David Gilbert <david dot gilbert at object-refinery dot com>
- To: mauve-patches at sources dot redhat dot com
- Date: Mon, 06 Sep 2004 20:43:02 +0100
- Subject: java.awt.geom.Rectangle2D
Attached are some tests for the java.awt.geom.Rectangle2D base class.
All checks pass for me using JamVM 1.1.4 and JDK 1.4:
dgilbert@linux42:~/workspace/mauve> java -cp .
gnu.testlet.SimpleTestHarness -file Rectangle2DTests.txt -debug
0 of 80 tests failed
dgilbert@linux42:~/workspace/mauve> jamvm -cp .
gnu.testlet.SimpleTestHarness -file Rectangle2DTests.txt -debug
0 of 80 tests failed
Regards,
Dave Gilbert
www.jfree.org
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
/**
* Some tests for the add() methods in the {@link Rectangle2D} class.
*/
public class add implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
// add(double, double)
Rectangle2D r = new Rectangle2D.Double();
r.add(1.0, 2.0);
harness.check(r.getX(), 0.0);
harness.check(r.getY(), 0.0);
harness.check(r.getWidth(), 1.0);
harness.check(r.getHeight(), 2.0);
// add(Point2D)
r = new Rectangle2D.Double();
r.add(new Point2D.Double(1.0, 2.0));
harness.check(r.getX(), 0.0);
harness.check(r.getY(), 0.0);
harness.check(r.getWidth(), 1.0);
harness.check(r.getHeight(), 2.0);
boolean pass = false;
try
{
r.add((Point2D) null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
// add(Rectangle2D)
r = new Rectangle2D.Double();
r.add(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
harness.check(r.getX(), 0.0);
harness.check(r.getY(), 0.0);
harness.check(r.getWidth(), 4.0);
harness.check(r.getHeight(), 6.0);
pass = false;
try
{
r.add((Rectangle2D) null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Verifies constant values for the {@link Rectangle2D} class.
*/
public class constants implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
harness.check(Rectangle2D.OUT_BOTTOM == 8);
harness.check(Rectangle2D.OUT_LEFT == 1);
harness.check(Rectangle2D.OUT_RIGHT == 4);
harness.check(Rectangle2D.OUT_TOP == 2);
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Some tests for the contains() method in the {@link Rectangle2D} class.
*/
public class contains implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
// contains(double, double)
Rectangle2D r = new Rectangle2D.Double();
harness.check(!r.contains(0.0, 0.0));
r = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
harness.check(r.contains(1.0, 2.0));
harness.check(!r.contains(1.0, 6.0));
harness.check(!r.contains(4.0, 2.0));
harness.check(!r.contains(4.0, 6.0));
// contains(double, double, double, double)
r = new Rectangle2D.Double();
harness.check(!r.contains(0.0, 0.0, 0.0, 0.0));
r = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
harness.check(r.contains(1.0, 2.0, 3.0, 4.0));
harness.check(!r.contains(1.0, 2.0, 4.0, 4.0));
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
//This file is part of Mauve.
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Tests the equals() method for the {@link Rectangle2D} class.
*/
public class equals
implements Testlet
{
/**
* Some checks for the equals() method.
*/
public void test(TestHarness harness)
{
Rectangle2D r1 = new Rectangle2D.Double();
Rectangle2D r2 = new Rectangle2D.Double();
harness.check(r1.equals(r2));
harness.check(r2.equals(r1));
harness.check(!r1.equals(null));
r1 = new Rectangle2D.Double(1.0, 0.0, 0.0, 0.0);
harness.check(!r1.equals(r2));
r2 = new Rectangle2D.Double(1.0, 0.0, 0.0, 0.0);
harness.check(r1.equals(r2));
r1 = new Rectangle2D.Double(1.0, 2.0, 0.0, 0.0);
harness.check(!r1.equals(r2));
r2 = new Rectangle2D.Double(1.0, 2.0, 0.0, 0.0);
harness.check(r1.equals(r2));
r1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 0.0);
harness.check(!r1.equals(r2));
r2 = new Rectangle2D.Double(1.0, 2.0, 3.0, 0.0);
harness.check(r1.equals(r2));
r1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
harness.check(!r1.equals(r2));
r2 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
harness.check(r1.equals(r2));
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
//This file is part of Mauve.
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Tests the getBounds2D() method for the {@link Rectangle2D} class.
*/
public class getBounds2D
implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
Rectangle2D r1 = new Rectangle2D.Double();
Rectangle2D r2 = r1.getBounds2D();
harness.check(r2.getX(), 0.0);
harness.check(r2.getY(), 0.0);
harness.check(r2.getWidth(), 0.0);
harness.check(r2.getHeight(), 0.0);
r1 = new Rectangle2D.Double(1.1, 2.2, 3.3, 4.4);
r2 = r1.getBounds2D();
harness.check(r2.getX(), 1.1);
harness.check(r2.getY(), 2.2);
harness.check(r2.getWidth(), 3.3);
harness.check(r2.getHeight(), 4.4);
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
//This file is part of Mauve.
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Some tests for the intersect() method in the {@link Rectangle2D} class.
*/
public class intersect
implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
Rectangle2D r1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
Rectangle2D r2 = new Rectangle2D.Double(2.0, 1.0, 3.0, 4.0);
Rectangle2D r3 = new Rectangle2D.Double();
Rectangle2D.intersect(r1, r2, r3);
harness.check(r3.getX(), 2.0);
harness.check(r3.getY(), 2.0);
harness.check(r3.getWidth(), 2.0);
harness.check(r3.getHeight(), 3.0);
boolean pass = false;
try
{
Rectangle2D.intersect(null, r2, r3);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
Rectangle2D.intersect(r1, null, r3);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
Rectangle2D.intersect(r1, r2, null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Checks that the intersects() method works correctly.
*/
public class intersects implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
Rectangle2D r = new Rectangle2D.Double(0.0, 0.0, 1.0, 1.0);
harness.check(!r.intersects(-1.0, -1.0, 1.0, 1.0));
harness.check(!r.intersects(-1.0, 0.0, 1.0, 1.0));
harness.check(!r.intersects(0.0, -1.0, 1.0, 1.0));
harness.check(r.intersects(0.0, 0.0, 1.0, 1.0));
r = new Rectangle2D.Double();
harness.check(!r.intersects(0.0, 0.0, 0.0, 0.0));
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com>
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Checks that the intersectsLine() method works correctly.
*/
public class intersectsLine implements Testlet {
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
Rectangle2D r = new Rectangle2D.Double(0.0, 0.0, 5.0, 10.0);
harness.check(r.intersectsLine(0.0, 0.0, 5.0, 0.0));
harness.check(r.intersectsLine(0.0, 0.0, 0.0, 10.0));
harness.check(r.intersectsLine(5.0, 0.0, 5.0, 10.0));
harness.check(r.intersectsLine(0.0, 10.0, 5.0, 10.0));
// segment that doesn't intersect
harness.check(!r.intersectsLine(-1.0, -1.0, -2.0, -2.0));
// segment passes through
harness.check(r.intersectsLine(-5.0, 2.0, 15.0, 2.0));
// segments that end at corners
harness.check(r.intersectsLine(-1.0, 0.0, 0.0, 0.0));
harness.check(r.intersectsLine(5.0, -1.0, 5.0, 0.0));
harness.check(r.intersectsLine(-1.0, 10.0, 0.0, 10.0));
harness.check(r.intersectsLine(5, 11.0, 5.0, 10.0));
// zero rectangle
r = new Rectangle2D.Double();
harness.check(!r.intersectsLine(0.0, 0.0, 0.0, 0.0));
boolean pass = false;
try
{
r.intersectsLine(null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
//This file is part of Mauve.
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Tests the setFrame() method for the {@link Rectangle2D} class.
*/
public class setFrame
implements Testlet
{
/**
* Run the checks using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
// setFrame(double, double, double, double)
Rectangle2D r1 = new Rectangle2D.Double();
r1.setFrame(1.0, 2.0, 3.0, 4.0);
harness.check(r1.getX(), 1.0);
harness.check(r1.getY(), 2.0);
harness.check(r1.getWidth(), 3.0);
harness.check(r1.getHeight(), 4.0);
}
}
//Tags: JDK1.2
//Copyright (C) 2004 David Gilbert (david.gilbert@object-refinery.com)
//This file is part of Mauve.
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.awt.geom.Rectangle2D;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.awt.geom.Rectangle2D;
/**
* Some tests for the union() method in the {@link Rectangle2D} class.
*/
public class union
implements Testlet
{
/**
* Runs the test using the specified harness.
*
* @param harness the test harness (<code>null</code> not permitted).
*/
public void test(TestHarness harness)
{
Rectangle2D r1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
Rectangle2D r2 = new Rectangle2D.Double(5.0, 6.0, 7.0, 8.0);
Rectangle2D r3 = new Rectangle2D.Double();
Rectangle2D.union(r1, r2, r3);
harness.check(r3.getX(), 1.0);
harness.check(r3.getY(), 2.0);
harness.check(r3.getWidth(), 11.0);
harness.check(r3.getHeight(), 12.0);
boolean pass = false;
try
{
Rectangle2D.union(null, r2, r3);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
Rectangle2D.union(r1, null, r3);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
pass = false;
try
{
Rectangle2D.union(r1, r2, null);
}
catch (NullPointerException e)
{
pass = true;
}
harness.check(pass);
}
}