Revision: 1031
Author: heuermh
Date: Fri Jul 23 13:43:12 2010
Log: increasing test coverage for PArea, back to only expected test failures
http://code.google.com/p/piccolo2d/source/detail?r=1031

Modified:
/piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/AbstractPNodeTest.java /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/PNodeTest.java /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathDoubleTest.java /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathFloatTest.java

=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java Fri Jul 23 11:55:49 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PArea.java Fri Jul 23 13:43:12 2010
@@ -38,24 +38,23 @@
  */
 public class PArea extends PShape
 {
-    private Area area;
+    private transient Area area;


     public PArea() {
-        super();
         area = new Area();
     }

     public PArea(final Shape shape) {
         if (shape == null) {
-            throw new IllegalArgumentException("shape must not be null");
+            throw new NullPointerException("shape must not be null");
         }
         this.area = new Area(shape);
     }

     public PArea(final Area area) {
         if (area == null) {
-            throw new IllegalArgumentException("area must not be null");
+            throw new NullPointerException("area must not be null");
         }
         this.area = new Area();
         this.area.add(area);
@@ -64,22 +63,22 @@

     public void add(final Area area) {
         this.area.add(area);
-        updateBounds();
+        updateBoundsFromShape();
     }

     public void exclusiveOr(final Area area) {
         this.area.exclusiveOr(area);
-        updateBounds();
+        updateBoundsFromShape();
     }

     public void intersect(final Area area) {
         this.area.intersect(area);
-        updateBounds();
+        updateBoundsFromShape();
     }

     public void subtract(final Area area) {
         this.area.subtract(area);
-        updateBounds();
+        updateBoundsFromShape();
     }

     public boolean isPolygonal() {
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java Fri Jul 23 11:55:49 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/main/java/org/piccolo2d/nodes/PPath.java Fri Jul 23 13:43:12 2010
@@ -31,6 +31,7 @@
 import java.awt.Shape;

 import java.awt.geom.AffineTransform;
+import java.awt.geom.Arc2D;
 import java.awt.geom.CubicCurve2D;
 import java.awt.geom.Ellipse2D;
 import java.awt.geom.Line2D;
@@ -85,6 +86,10 @@
     }


+ public static PPath createArc(final float x, final float y, final float width, final float height, final float start, final float extent, final int type) { + return new PPath.Float(new Arc2D.Float(x, y, width, height, start, extent, type));
+    }
+
public static PPath createCubicCurve(final float x1, final float y1, final float ctrlx1, final float ctrly1, final float ctrlx2, final float ctrly2, final float x2, final float y2) { return new PPath.Float(new CubicCurve2D.Float(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
     }
@@ -118,6 +123,9 @@
return new PPath.Float(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
     }

+ public static PPath createArc(final double x, final double y, final double width, final double height, final double start, final double extent, final int type) { + return new PPath.Double(new Arc2D.Double(x, y, width, height, start, extent, type));
+    }

public static PPath createCubicCurve(final double x1, final double y1, final double ctrlx1, final double ctrly1, final double ctrlx2, final double ctrly2, final double x2, final double y2) { return new PPath.Double(new CubicCurve2D.Double(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2));
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/AbstractPNodeTest.java Fri Jul 23 12:41:40 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/AbstractPNodeTest.java Fri Jul 23 13:43:12 2010
@@ -70,8 +70,8 @@
  */
 public abstract class AbstractPNodeTest extends TestCase {

-    private MockPropertyChangeListener mockListener;
-    private PNode node;
+    protected MockPropertyChangeListener mockListener;
+    protected PNode node;

     protected void setUp() {
         node = createNode();
@@ -140,29 +140,6 @@
         assertEquals(10, node.getGlobalTranslation().getY(), 0);
         assertEquals(0.25, node.getGlobalScale(), 0);
     }
-
-    public void testFindIntersectingNodes() {
-        final PNode c = new PNode();
-
-        node.addChild(c);
-        node.setBounds(0, 0, 100, 100);
-        c.setBounds(0, 0, 100, 100);
-        c.scale(200);
-
-        ArrayList found = new ArrayList();
-        final Rectangle2D rect2d = new Rectangle2D.Double(50, 50, 10, 10);
-        node.findIntersectingNodes(rect2d, found);
-
-        assertEquals(found.size(), 2);
-        assertEquals(rect2d.getHeight(), 10, 0);
-        found = new ArrayList();
-
-        final PBounds bounds = new PBounds(50, 50, 10, 10);
-        node.findIntersectingNodes(bounds, found);
-
-        assertEquals(found.size(), 2);
-        assertEquals(bounds.getHeight(), 10, 0);
-    }

     public void testRemoveNonexistantListener() {
         node.removeInputEventListener(new PBasicInputEventHandler());
@@ -829,93 +806,6 @@
             // expected
         }
     }
-
- // todo: most of these pixel-perfect tests probably will not work on subclasses
-
-    public void testSetTransparency1MeansInvisible() {
-        node.setBounds(0, 0, 100, 100);
-        node.setVisible(true);
-        node.setPaint(Color.RED);
-
-        final PCanvas canvas = buildCanvasContainingNode(node);
-
- final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); - final Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
-
-        canvas.paintComponent(g);
-        node.setTransparency(1f);
-        assertEquals(Color.RED.getRGB(), img.getRGB(10, 10));
-
-        node.setTransparency(0f);
-        canvas.paintComponent(g);
-        assertEquals(Color.WHITE.getRGB(), img.getRGB(10, 10));
-
-    }
-
-    private PCanvas buildCanvasContainingNode(final PNode node) {
-        final PCanvas canvas = new PCanvas();
-        canvas.setSize(100, 100);
-        canvas.getLayer().addChild(node);
-        return canvas;
-    }
-
-    public void testPaintColourIsRespectedOnPaint() {
- final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); - final Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
-
-        node.setPaint(Color.RED);
-        node.setBounds(0, 0, 100, 100);
-
-        final PCanvas canvas = buildCanvasContainingNode(node);
-        canvas.paintComponent(g);
-
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
-    }
-
-    public void testToImageReturnsValidImage() {
-        node.setBounds(0, 0, 10, 10);
-        node.setPaint(Color.RED);
-
-        // Really don't like casting here, but... without changing the
-        // interface, I don't see a choice
-        final BufferedImage img = (BufferedImage) node.toImage();
-
-        assertEquals(10, img.getHeight(null));
-        assertEquals(10, img.getWidth(null));
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
-        assertEquals(Color.RED.getRGB(), img.getRGB(9, 0));
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 9));
-        assertEquals(Color.RED.getRGB(), img.getRGB(9, 9));
-    }
-
- public void testToImageUsesFullBoundsWhenConvertingImage() throws IOException {
-        node.setBounds(0, 0, 50, 50);
-        PNode child1 = new PNode();
-        child1.setBounds(0, 0, 100, 50);
-        child1.setPaint(Color.RED);
-        node.addChild(child1);
-
-        PNode child2 = new PNode();
-        child2.setBounds(0, 0, 50, 100);
-        child2.setPaint(Color.BLUE);
-        node.addChild(child2);
-
-        BufferedImage image = (BufferedImage) node.toImage();
-        assertNotNull(image);
-        assertEquals(100, image.getWidth());
-        assertEquals(100, image.getHeight());
-        assertEquals(Color.RED.getRGB(), image.getRGB(99, 1));
-
- //This line fails if PNode.toImage uses getWidth() rather than getFullBounds().getWidth()
-        assertEquals(Color.BLUE.getRGB(), image.getRGB(1, 99));
-    }
-
-    public void testToImageWillAcceptBackgroundPaint() {
-        node.setBounds(0, 0, 10, 10);
-
- final BufferedImage img = (BufferedImage) node.toImage(10, 10, Color.BLUE);
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(5, 5));
-    }

     public void testToImageResultsInDesiredSizeImage() {
         node.setBounds(0, 0, 10, 10);
@@ -924,76 +814,6 @@
         assertEquals(40, img.getHeight(null));
         assertEquals(20, img.getWidth(null));
     }
-
-    public void testToImageWithBackgroundColorGivenReturnsValidImage() {
-        node.setBounds(0, 0, 10, 10);
-        node.setPaint(Color.RED);
-
- final BufferedImage img = (BufferedImage) node.toImage(20, 40, Color.BLUE);
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(15, 25));
-    }
-
-    public void testToImageScalesNodeAsBigAsCanBe() throws IOException {
-        node.setBounds(0, 0, 10, 10);
-        node.setPaint(Color.RED);
-
- final BufferedImage img = (BufferedImage) node.toImage(20, 40, Color.BLUE);
-
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
-        assertEquals(Color.RED.getRGB(), img.getRGB(19, 0));
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 19));
-        assertEquals(Color.RED.getRGB(), img.getRGB(19, 19));
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(0, 20));
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(19, 20));
-    }
-
- public void testToImageScalesAccordingToExactFitStrategy() throws IOException {
-        node.setBounds(0, 0, 10, 10);
-        node.setPaint(Color.RED);
-
- final BufferedImage img = (BufferedImage) node.toImage(new BufferedImage(20, 40, BufferedImage.TYPE_INT_RGB),
-                Color.BLUE, PNode.FILL_STRATEGY_EXACT_FIT);
-
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
-        assertEquals(Color.RED.getRGB(), img.getRGB(19, 0));
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 39));
-        assertEquals(Color.RED.getRGB(), img.getRGB(19, 39));
-
-    }
-
- public void testToImageScalesAccordingToAspectCoverStrategy() throws IOException {
-        node.setBounds(0, 0, 10, 10);
-        node.setPaint(Color.RED);
-
-        PNode blueSquare = new PNode();
-        blueSquare.setPaint(Color.BLUE);
-        blueSquare.setBounds(0, 0, 5, 5);
-        node.addChild(blueSquare);
-
-        PNode greenSquare = new PNode();
-        greenSquare.setPaint(Color.GREEN);
-        greenSquare.setBounds(5, 5, 5, 5);
-        node.addChild(greenSquare);
-
- final BufferedImage img = (BufferedImage) node.toImage(new BufferedImage(20, 40, BufferedImage.TYPE_INT_RGB),
-                Color.BLUE, PNode.FILL_STRATEGY_EXACT_FIT);
-
-        assertEquals(Color.RED.getRGB(), img.getRGB(11, 19));
-        assertEquals(Color.RED.getRGB(), img.getRGB(9, 20));
-        assertEquals(Color.RED.getRGB(), img.getRGB(0, 20));
-        assertEquals(Color.RED.getRGB(), img.getRGB(9, 39));
-
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(9, 19));
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(0, 0));
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(0, 19));
-        assertEquals(Color.BLUE.getRGB(), img.getRGB(9, 0));
-
-        assertEquals(Color.GREEN.getRGB(), img.getRGB(10, 20));
-        assertEquals(Color.GREEN.getRGB(), img.getRGB(19, 20));
-        assertEquals(Color.GREEN.getRGB(), img.getRGB(10, 39));
-        assertEquals(Color.GREEN.getRGB(), img.getRGB(19, 39));
-    }

     public void testGetPickableShouldDefaultToTrue() {
         assertTrue(node.getPickable());
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/PNodeTest.java Fri Jul 23 12:24:02 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/PNodeTest.java Fri Jul 23 13:43:12 2010
@@ -133,6 +133,29 @@

         layoutNode1.getFullBoundsReference();
     }
+
+    public void testFindIntersectingNodes() {
+        final PNode c = new PNode();
+
+        node.addChild(c);
+        node.setBounds(0, 0, 100, 100);
+        c.setBounds(0, 0, 100, 100);
+        c.scale(200);
+
+        ArrayList found = new ArrayList();
+        final Rectangle2D rect2d = new Rectangle2D.Double(50, 50, 10, 10);
+        node.findIntersectingNodes(rect2d, found);
+
+        assertEquals(found.size(), 2);
+        assertEquals(rect2d.getHeight(), 10, 0);
+        found = new ArrayList();
+
+        final PBounds bounds = new PBounds(50, 50, 10, 10);
+        node.findIntersectingNodes(bounds, found);
+
+        assertEquals(found.size(), 2);
+        assertEquals(bounds.getHeight(), 10, 0);
+    }

     public void testCenterFullBoundsOnPointWorksAsExpected() {
         final PNode parent = buildComplexSquareNode();
@@ -251,4 +274,152 @@
         final PPickPath path = canvas.getCamera().pick(5, 5, 5);
         assertSame(node1, path.getPickedNode());
     }
-}
+
+    public void testSetTransparency1MeansInvisible() {
+        node.setBounds(0, 0, 100, 100);
+        node.setVisible(true);
+        node.setPaint(Color.RED);
+
+        final PCanvas canvas = buildCanvasContainingNode(node);
+
+ final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); + final Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
+
+        canvas.paintComponent(g);
+        node.setTransparency(1f);
+        assertEquals(Color.RED.getRGB(), img.getRGB(10, 10));
+
+        node.setTransparency(0f);
+        canvas.paintComponent(g);
+        assertEquals(Color.WHITE.getRGB(), img.getRGB(10, 10));
+
+    }
+
+    public void testPaintColourIsRespectedOnPaint() {
+ final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); + final Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);
+
+        node.setPaint(Color.RED);
+        node.setBounds(0, 0, 100, 100);
+
+        final PCanvas canvas = buildCanvasContainingNode(node);
+        canvas.paintComponent(g);
+
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
+    }
+
+    public void testToImageReturnsValidImage() {
+        node.setBounds(0, 0, 10, 10);
+        node.setPaint(Color.RED);
+
+        // Really don't like casting here, but... without changing the
+        // interface, I don't see a choice
+        final BufferedImage img = (BufferedImage) node.toImage();
+
+        assertEquals(10, img.getHeight(null));
+        assertEquals(10, img.getWidth(null));
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
+        assertEquals(Color.RED.getRGB(), img.getRGB(9, 0));
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 9));
+        assertEquals(Color.RED.getRGB(), img.getRGB(9, 9));
+    }
+
+ public void testToImageUsesFullBoundsWhenConvertingImage() throws IOException {
+        node.setBounds(0, 0, 50, 50);
+        PNode child1 = new PNode();
+        child1.setBounds(0, 0, 100, 50);
+        child1.setPaint(Color.RED);
+        node.addChild(child1);
+
+        PNode child2 = new PNode();
+        child2.setBounds(0, 0, 50, 100);
+        child2.setPaint(Color.BLUE);
+        node.addChild(child2);
+
+        BufferedImage image = (BufferedImage) node.toImage();
+        assertNotNull(image);
+        assertEquals(100, image.getWidth());
+        assertEquals(100, image.getHeight());
+        assertEquals(Color.RED.getRGB(), image.getRGB(99, 1));
+
+ //This line fails if PNode.toImage uses getWidth() rather than getFullBounds().getWidth()
+        assertEquals(Color.BLUE.getRGB(), image.getRGB(1, 99));
+    }
+
+    public void testToImageWillAcceptBackgroundPaint() {
+        node.setBounds(0, 0, 10, 10);
+
+ final BufferedImage img = (BufferedImage) node.toImage(10, 10, Color.BLUE);
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(5, 5));
+    }
+
+    public void testToImageWithBackgroundColorGivenReturnsValidImage() {
+        node.setBounds(0, 0, 10, 10);
+        node.setPaint(Color.RED);
+
+ final BufferedImage img = (BufferedImage) node.toImage(20, 40, Color.BLUE);
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(15, 25));
+    }
+
+    public void testToImageScalesNodeAsBigAsCanBe() throws IOException {
+        node.setBounds(0, 0, 10, 10);
+        node.setPaint(Color.RED);
+
+ final BufferedImage img = (BufferedImage) node.toImage(20, 40, Color.BLUE);
+
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
+        assertEquals(Color.RED.getRGB(), img.getRGB(19, 0));
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 19));
+        assertEquals(Color.RED.getRGB(), img.getRGB(19, 19));
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(0, 20));
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(19, 20));
+    }
+
+ public void testToImageScalesAccordingToExactFitStrategy() throws IOException {
+        node.setBounds(0, 0, 10, 10);
+        node.setPaint(Color.RED);
+
+ final BufferedImage img = (BufferedImage) node.toImage(new BufferedImage(20, 40, BufferedImage.TYPE_INT_RGB),
+                Color.BLUE, PNode.FILL_STRATEGY_EXACT_FIT);
+
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 0));
+        assertEquals(Color.RED.getRGB(), img.getRGB(19, 0));
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 39));
+        assertEquals(Color.RED.getRGB(), img.getRGB(19, 39));
+
+    }
+
+ public void testToImageScalesAccordingToAspectCoverStrategy() throws IOException {
+        node.setBounds(0, 0, 10, 10);
+        node.setPaint(Color.RED);
+
+        PNode blueSquare = new PNode();
+        blueSquare.setPaint(Color.BLUE);
+        blueSquare.setBounds(0, 0, 5, 5);
+        node.addChild(blueSquare);
+
+        PNode greenSquare = new PNode();
+        greenSquare.setPaint(Color.GREEN);
+        greenSquare.setBounds(5, 5, 5, 5);
+        node.addChild(greenSquare);
+
+ final BufferedImage img = (BufferedImage) node.toImage(new BufferedImage(20, 40, BufferedImage.TYPE_INT_RGB),
+                Color.BLUE, PNode.FILL_STRATEGY_EXACT_FIT);
+
+        assertEquals(Color.RED.getRGB(), img.getRGB(11, 19));
+        assertEquals(Color.RED.getRGB(), img.getRGB(9, 20));
+        assertEquals(Color.RED.getRGB(), img.getRGB(0, 20));
+        assertEquals(Color.RED.getRGB(), img.getRGB(9, 39));
+
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(9, 19));
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(0, 0));
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(0, 19));
+        assertEquals(Color.BLUE.getRGB(), img.getRGB(9, 0));
+
+        assertEquals(Color.GREEN.getRGB(), img.getRGB(10, 20));
+        assertEquals(Color.GREEN.getRGB(), img.getRGB(19, 20));
+        assertEquals(Color.GREEN.getRGB(), img.getRGB(10, 39));
+        assertEquals(Color.GREEN.getRGB(), img.getRGB(19, 39));
+    }
+}
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java Fri Jul 23 12:41:40 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PAreaTest.java Fri Jul 23 13:43:12 2010
@@ -28,13 +28,265 @@
  */
 package org.piccolo2d.nodes;

+import java.awt.Shape;
+
+import java.awt.geom.Area;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+
 /**
  * Unit test for PArea.
  */
 public class PAreaTest extends AbstractPShapeTest {

+    private static final double TOLERANCE = 0.0001d;
+
     /** {...@inheritdoc} */
     protected PShape createShapeNode() {
         return new PArea();
     }
-}
+
+    public void testNoArgConstructor() {
+        assertNotNull(new PArea());
+    }
+
+    public void testShapeConstructor() {
+ assertNotNull(new PArea(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d)));
+    }
+
+    public void testShapeConstructorNullArgument() {
+        try {
+            new PArea((Shape) null);
+            fail("ctr((Shape) null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testAreaConstructor() {
+        assertNotNull(new PArea(new Area()));
+    }
+
+    public void testAreaConstructorNullArgument() {
+        try {
+            new PArea((Area) null);
+            fail("ctr((Area) null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testAdd() {
+        PArea area = new PArea();
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect1);
+
+        // todo:  shouldn't this be width + 2 * strokeWidth?
+        assertEquals(151.0d, area.getWidth(), TOLERANCE);
+        assertEquals(101.0, area.getHeight(), TOLERANCE);
+ assertTrue(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertTrue(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertTrue(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testAddNoStroke() {
+        PArea area = new PArea();
+        area.setStroke(null);
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect1);
+
+        assertEquals(150.0d, area.getWidth(), TOLERANCE);
+        assertEquals(100.0, area.getHeight(), TOLERANCE);
+ assertFalse(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testAddNullArgument() {
+        PArea area = new PArea();
+        try {
+            area.add(null);
+            fail("add(null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testExclusiveOr() {
+        PArea area = new PArea();
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.exclusiveOr(rect1);
+
+        assertEquals(151.0d, area.getWidth(), TOLERANCE);
+        assertEquals(101.0, area.getHeight(), TOLERANCE);
+ assertTrue(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertTrue(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testExclusiveOrNoStroke() {
+        PArea area = new PArea();
+        area.setStroke(null);
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.exclusiveOr(rect1);
+
+        assertEquals(150.0d, area.getWidth(), TOLERANCE);
+        assertEquals(100.0, area.getHeight(), TOLERANCE);
+ assertFalse(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testExclusiveOrNullArgument() {
+        PArea area = new PArea();
+        try {
+            area.exclusiveOr(null);
+            fail("exclusiveOr(null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testIntersect() {
+        PArea area = new PArea();
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.intersect(rect1);
+
+        assertEquals(51.0d, area.getWidth(), TOLERANCE);
+        assertEquals(101.0, area.getHeight(), TOLERANCE);
+ assertFalse(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertTrue(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testIntersectNoStroke() {
+        PArea area = new PArea();
+        area.setStroke(null);
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.intersect(rect1);
+
+        assertEquals(50.0d, area.getWidth(), TOLERANCE);
+        assertEquals(100.0, area.getHeight(), TOLERANCE);
+ assertFalse(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testIntersectNullArgument() {
+        PArea area = new PArea();
+        try {
+            area.intersect(null);
+            fail("intersect(null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testSubtract() {
+        PArea area = new PArea();
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.subtract(rect1);
+
+        assertEquals(51.0d, area.getWidth(), TOLERANCE);
+        assertEquals(101.0, area.getHeight(), TOLERANCE);
+ assertTrue(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testSubtractNoStroke() {
+        PArea area = new PArea();
+        area.setStroke(null);
+        assertEquals(0.0d, area.getWidth(), TOLERANCE);
+        assertEquals(0.0d, area.getHeight(), TOLERANCE);
+
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        area.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        area.subtract(rect1);
+
+        assertEquals(50.0d, area.getWidth(), TOLERANCE);
+        assertEquals(100.0, area.getHeight(), TOLERANCE);
+ assertFalse(area.intersects(new Rectangle2D.Double(10.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(60.0d, 95.0d, 10.0d, 10.0d))); + assertFalse(area.intersects(new Rectangle2D.Double(110.0d, 95.0d, 10.0d, 10.0d)));
+    }
+
+    public void testSubtractNullArgument() {
+        PArea area = new PArea();
+        try {
+            area.subtract(null);
+            fail("subtract(null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testIsPolygonal() {
+ assertTrue(new PArea(new Rectangle2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isPolygonal()); + assertTrue(new PArea(new Line2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isPolygonal()); + assertFalse(new PArea(new Ellipse2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isPolygonal());
+    }
+
+    public void testIsRectangular() {
+ assertTrue(new PArea(new Rectangle2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isRectangular()); + assertTrue(new PArea(new Line2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isRectangular()); + assertFalse(new PArea(new Ellipse2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isRectangular());
+    }
+
+    public void testIsSingular() {
+ assertTrue(new PArea(new Rectangle2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isSingular()); + assertTrue(new PArea(new Line2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isSingular()); + assertTrue(new PArea(new Ellipse2D.Double(0.0d, 0.0d, 50.0d, 100.0d)).isSingular());
+
+        PArea exclusiveOr = new PArea();
+ Area rect0 = new Area(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d));
+        exclusiveOr.add(rect0);
+ Area rect1 = new Area(new Rectangle2D.Double(50.0d, 0.0d, 100.0d, 100.0d));
+        exclusiveOr.exclusiveOr(rect1);
+
+        assertFalse(exclusiveOr.isSingular());
+    }
+}
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathDoubleTest.java Fri Jul 23 12:41:40 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathDoubleTest.java Fri Jul 23 13:43:12 2010
@@ -28,6 +28,11 @@
  */
 package org.piccolo2d.nodes;

+import java.awt.Shape;
+
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+
 /**
  * Unit test for PPath.Double.
  */
@@ -37,4 +42,36 @@
     protected PShape createShapeNode() {
         return new PPath.Double();
     }
-}
+
+    public void testNoArgConstructor() {
+        assertNotNull(new PPath.Double());
+    }
+
+    public void testShapeConstructor() {
+ assertNotNull(new PPath.Double(new Rectangle2D.Double(0.0d, 0.0d, 100.0d, 100.0d )));
+    }
+
+    public void testShapeConstructorNullArgument() {
+        try {
+            new PPath.Double((Shape) null);
+            fail("ctr((Shape) null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testPathConstructor() {
+        assertNotNull(new PPath.Double(new Path2D.Double()));
+    }
+
+    public void testPathConstructorNullArgument() {
+        try {
+            new PPath.Double((Path2D) null);
+            fail("ctr((Path2D) null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+}
=======================================
--- /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathFloatTest.java Fri Jul 23 12:41:40 2010 +++ /piccolo2d.java/branches/ppath-refactoring/core/src/test/java/org/piccolo2d/nodes/PPathFloatTest.java Fri Jul 23 13:43:12 2010
@@ -28,6 +28,11 @@
  */
 package org.piccolo2d.nodes;

+import java.awt.Shape;
+
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+
 /**
  * Unit test for PPath.Float.
  */
@@ -37,4 +42,36 @@
     protected PShape createShapeNode() {
         return new PPath.Float();
     }
-}
+
+    public void testNoArgConstructor() {
+        assertNotNull(new PPath.Float());
+    }
+
+    public void testShapeConstructor() {
+ assertNotNull(new PPath.Float(new Rectangle2D.Float(0.0f, 0.0f, 100.0f, 100.0f)));
+    }
+
+    public void testShapeConstructorNullArgument() {
+        try {
+            new PPath.Float((Shape) null);
+            fail("ctr((Shape) null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+
+    public void testPathConstructor() {
+        assertNotNull(new PPath.Float(new Path2D.Float()));
+    }
+
+    public void testPathConstructorNullArgument() {
+        try {
+            new PPath.Float((Path2D) null);
+            fail("ctr((Path2D) null) expected NullPointerException");
+        }
+        catch (NullPointerException e) {
+            // expected
+        }
+    }
+}

--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to