Author: allain.lalonde
Date: Wed Jul 15 12:31:15 2009
New Revision: 474

Added:
     
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PPanEventHandlerTest.java
Modified:
     
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java
     
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java

Log:
Added some trivial tests for PPanEventHandler and added come accesors to it  
for maxAutoPanSpeed and minAutoPanSpeed.

Also, cleaned up test for PAffineTransform.

Modified:  
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java
==============================================================================
---  
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java
   
(original)
+++  
piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/event/PPanEventHandler.java
   
Wed Jul 15 12:31:15 2009
@@ -102,6 +102,26 @@
      public void setMaxAutopanSpeed(double maxAutopanSpeed) {
          this.maxAutopanSpeed = maxAutopanSpeed;
      }
+
+    /**
+     * Returns the minAutoPan speed in pixels per second.
+     *
+     * @param minAutopanSpeed
+     * @return minAutopanSpeed in pixels
+     */
+    public double getMinAutoPanSpeed() {
+        return minAutopanSpeed;
+    }
+
+    /**
+     * Returns the maxAutoPan speed in pixels per second.
+     *
+     * @param maxAutopanSpeed
+     * @return maxAutopanSpeed in pixels
+     */
+    public double getMaxAutoPanSpeed() {
+        return maxAutopanSpeed;
+    }

      /**
       * Do auto panning even when the mouse is not moving.

Added:  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PPanEventHandlerTest.java
==============================================================================
--- (empty file)
+++  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/event/PPanEventHandlerTest.java
       
Wed Jul 15 12:31:15 2009
@@ -0,0 +1,38 @@
+package edu.umd.cs.piccolo.event;
+
+import junit.framework.TestCase;
+
+public class PPanEventHandlerTest extends TestCase {
+    private PPanEventHandler handler;
+
+    public void setUp() {
+        handler = new PPanEventHandler();
+    }
+
+    public void testAutoPanIsTrueByDefault() {
+        assertTrue(handler.getAutopan());
+    }
+
+    public void testSetAutoPanPersists() {
+        handler.setAutopan(true);
+        assertTrue(handler.getAutopan());
+    }
+
+    public void testDefaultMinAutoPanSpeed() {
+        assertEquals(250, handler.getMinAutoPanSpeed(), 0.0000001);
+    }
+
+    public void testMinAutoPanSpeedPersists() {
+        handler.setMinAutopanSpeed(10);
+        assertEquals(10, handler.getMinAutoPanSpeed(), 0.000001);
+    }
+
+    public void testMaxDefaultAutoPanSpeed() {
+        assertEquals(250, handler.getMinAutoPanSpeed(), 0.0000001);
+    }
+
+    public void testMaxAutoPanSpeedPersists() {
+        handler.setMaxAutopanSpeed(10);
+        assertEquals(10, handler.getMaxAutoPanSpeed(), 0.000001);
+    }
+}

Modified:  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java
==============================================================================
---  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java
        
(original)
+++  
piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/util/PAffineTransformTest.java
        
Wed Jul 15 12:31:15 2009
@@ -40,9 +40,9 @@
      public PAffineTransformTest(String aName) {
          super(aName);
      }
-
+
      public void setUp() {
-        at = new PAffineTransform();
+        at = new PAffineTransform();
      }

      public void testRotation() {
@@ -52,7 +52,7 @@
          assertEquals(at.getRotation(), Math.toRadians(90), 0.000000001);
      }

-    public void testScale() {
+    public void testScale() {
          at.scaleAboutPoint(0.45, 0, 1);
          assertEquals(at.getScale(), 0.45, 0.000000001);
          at.setScale(0.11);
@@ -60,49 +60,50 @@
      }

      public void testTransformRectLeavesEmptyBoundsEmpty() {
-        PBounds b1 = new PBounds();
+        PBounds b1 = new PBounds();
          at.scale(0.5, 0.5);
          at.translate(100, 50);

          at.transform(b1, b1);
          assertTrue(b1.isEmpty());
      }
-
+
      public void testTransformRect() {
          PBounds b1 = new PBounds(0, 0, 100, 80);
          PBounds b2 = new PBounds(100, 100, 100, 80);
-
+
          at.scale(0.5, 0.5);
          at.translate(100, 50);

          at.transform(b1, b1);
          at.transform(b2, b2);
-
-        assertSameBounds(new PBounds(50, 25, 50, 40), b1);
-        assertSameBounds(new PBounds(100, 75, 50, 40), b2);
-
+
+        assertEquals(new PBounds(50, 25, 50, 40), b1);
+        assertEquals(new PBounds(100, 75, 50, 40), b2);
+
          at.inverseTransform(b1, b1);
          at.inverseTransform(b2, b2);

-        assertSameBounds(new PBounds(0, 0, 100, 80), b1);
-        assertSameBounds(new PBounds(100, 100, 100, 80), b2);
+        assertEquals(new PBounds(0, 0, 100, 80), b1);
+        assertEquals(new PBounds(100, 100, 100, 80), b2);
      }
-
+
      public void testThrowsExceptionWhenSetting0Scale() {
-        try {
+        try {
              at.setScale(0);
              fail("Setting 0 scale should throw exception");
-        } catch (RuntimeException e) {
+        }
+        catch (RuntimeException e) {
              // expected
          }
      }
-
+
      public void testSetOffsetLeavesRotationUntouched() {
-        at.setRotation(Math.PI);
+        at.setRotation(Math.PI);
          at.setOffset(100, 50);
          assertEquals(Math.PI, at.getRotation(), 0.001);
      }
-
+
      public void testTransformDimensionWorks() {
          Dimension d1 = new Dimension(100, 50);
          at.setScale(2);
@@ -110,34 +111,33 @@
          at.transform(d1, d2);
          assertEquals(new Dimension(200, 100), d2);
      }
-
+
      public void testTransformDimensionWorksWithSecondParamNull() {
          Dimension d1 = new Dimension(100, 50);
          at.setScale(2);
          Dimension2D d2 = at.transform(d1, null);
          assertEquals(new Dimension(200, 100), d2);
      }
-
-    private final void assertSameBounds(PBounds expected, PBounds actual) {
-        assertSameBounds(expected, actual, 0.0000001);
-    }
-
-    private final void assertSameBounds(PBounds expected, PBounds actual,  
double errorRate) {
-        assertTrue("Expected " + expected + " but was " + actual,  
comparisonScore(expected, actual) > (1d-errorRate));
+
+    private final void assertEquals(PBounds expected, PBounds actual) {
+        assertEquals(expected, actual, 0.0000001);
+    }
+
+    private final void assertEquals(PBounds expected, PBounds actual,  
double errorRate) {
+        assertTrue("Expected " + expected + " but was " + actual,  
comparisonScore(expected, actual) > (1d - errorRate));
      }
-
-
+
      // % of area within full bounds covered by intersection or the two  
bounds.
      // exactly covering would be 1 no overlap would be 0
-    private final double comparisonScore(PBounds b1, PBounds b2) {
+    private final double comparisonScore(PBounds b1, PBounds b2) {
          PBounds intersection = new PBounds();
          PBounds union = new PBounds();
          PBounds.intersect(b1, b2, intersection);
-        PBounds.intersect(b1, b2, union);
-
+        PBounds.intersect(b1, b2, union);
+
          return area(intersection) / area(union);
      }
-
+
      private final double area(PBounds b) {
          return b.getWidth() * b.getHeight();
      }

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

Reply via email to