[OpenLayers-Commits] r2352 - in sandbox/vector-2.4: lib/OpenLayers/Geometry tests tests/Geometry

commits at openlayers.org commits at openlayers.org
Mon Mar 5 17:40:08 EST 2007


Author: sderle
Date: 2007-03-05 17:40:06 -0500 (Mon, 05 Mar 2007)
New Revision: 2352

Added:
   sandbox/vector-2.4/tests/Geometry/test_Curve.html
Modified:
   sandbox/vector-2.4/lib/OpenLayers/Geometry/Curve.js
   sandbox/vector-2.4/tests/list-tests.html
Log:
Add tests for OpenLayers.Geometry.Curve.

Modified: sandbox/vector-2.4/lib/OpenLayers/Geometry/Curve.js
===================================================================
--- sandbox/vector-2.4/lib/OpenLayers/Geometry/Curve.js	2007-03-05 22:32:10 UTC (rev 2351)
+++ sandbox/vector-2.4/lib/OpenLayers/Geometry/Curve.js	2007-03-05 22:40:06 UTC (rev 2352)
@@ -30,6 +30,7 @@
                 this.addPoint(points[i]);
             }
         }
+        // TODO: check to see if the path has more than 1 point?
                 
         this.bounds = this.getBounds();
     },
@@ -109,6 +110,8 @@
      */
     removePoint: function(point){
         this.path = OpenLayers.Util.removeItem(this.path, point);
+        // TODO: does the simple equality test in removeItem() actually make sense here?
+        // TODO: check to see if the path has more than 1 point?
     },
     
     /**
@@ -129,4 +132,4 @@
     
     /** @final @type String */
     CLASS_NAME: "OpenLayers.Geometry.Curve"
-});
\ No newline at end of file
+});

Added: sandbox/vector-2.4/tests/Geometry/test_Curve.html
===================================================================
--- sandbox/vector-2.4/tests/Geometry/test_Curve.html	                        (rev 0)
+++ sandbox/vector-2.4/tests/Geometry/test_Curve.html	2007-03-05 22:40:06 UTC (rev 2352)
@@ -0,0 +1,84 @@
+<html>
+<head>
+  <script src="../../lib/OpenLayers.js"></script>
+  <script type="text/javascript"><!--
+    var curve;
+    var path = [new OpenLayers.Geometry.Point(10,10), new OpenLayers.Geometry.Point(0,0)];
+        
+    function test_01_Curve_constructor (t) {
+        t.plan( 3 );
+        curve = new OpenLayers.Geometry.Curve();
+        t.ok( curve instanceof OpenLayers.Geometry.Curve, "new OpenLayers.Geometry.Curve returns curve object" );
+        t.eq( curve.CLASS_NAME, "OpenLayers.Geometry.Curve", "curve.CLASS_NAME is set correctly");
+        t.eq( curve.path, [], "curve.path is set correctly");
+    }
+
+    function test_01a_Curve_constructor (t) {
+        t.plan( 2 );
+        curve = new OpenLayers.Geometry.Curve(path);
+        t.ok( curve instanceof OpenLayers.Geometry.Curve, "new OpenLayers.Geometry.Curve returns curve object" );
+        t.eq( curve.path.length, 2, "curve.path.length is set correctly");
+    }
+
+    function test_02_Curve_clone (t) {
+        t.plan( 2 );
+        curve = new OpenLayers.Geometry.Curve(path);
+        curve2 = curve.clone(); 
+        t.ok( curve2 instanceof OpenLayers.Geometry.Curve, "curve.clone() returns curve object" );
+        t.eq( curve2.path.length, 2, "curve2.path.length is set correctly");
+    }
+
+    function test_03_Curve_getBounds (t) {
+        t.plan(5);
+        curve = new OpenLayers.Geometry.Curve(path);
+        bounds = curve.getBounds();
+        t.ok( bounds instanceof OpenLayers.Bounds, "curve.getBounds returns Bounds object" );
+        t.eq( bounds.left, 0, "left bound is 0" );
+        t.eq( bounds.bottom, 0, "bottom bound is 0" );
+        t.eq( bounds.right, 10, "right bound is 10" );
+        t.eq( bounds.top, 10, "top bound is 10" );
+    }
+
+    function test_04_Curve_addPoint (t) {
+        t.plan( 6 );
+        curve = new OpenLayers.Geometry.Curve(path);
+        curve.addPoint(new OpenLayers.Geometry.Point(20,30));
+        bounds = curve.getBounds();
+        t.eq( bounds.top, 30, "top bound is 30 after addPoint" );
+        t.eq( bounds.right, 20, "right bound is 20 after addPoint" );
+        curve.addPoint(new OpenLayers.Geometry.Point(-20,-30), 1);
+        bounds = curve.getBounds();
+        t.eq( bounds.bottom, -30, "bottom bound is -30 after 2nd addPoint" );
+        t.eq( bounds.left, -20, "left bound is 20 after 2nd addPoint" );
+        t.eq( curve.path[1].lon, -20,  "new point.lon is -20 (index worked)" );
+        t.eq( curve.path[1].lat, -30,  "new point.lat is -30 (index worked)" );
+    }
+
+    function test_05_Curve_removePoint (t) {
+        t.plan( 3 );
+        curve = new OpenLayers.Geometry.Curve(path);
+        curve.removePoint(curve.path[1]);
+        // N.B. a curve should never really be allowed to have just
+        // one point
+        t.eq( curve.path.length, 1, "curve.path.length is smaller after removePoint" );
+        bounds = curve.getBounds();
+        t.eq( bounds.left, 10, "left bound is 10 after removePoint" );
+        t.eq( bounds.bottom, 10, "bottom bound is 10 after removePoint" );
+    }
+
+    /****
+    // TODO: broken until OL.Util.length() is implemented
+    function test_06_Curve_getLength (t) {
+        t.plan( 1 );
+        curve = new OpenLayers.Geometry.Curve(path);
+        t.fail(curve.getLength().toFixed(5) == Math.sqrt(200).toFixed(5),
+                "curve.getLength returns a reasonably accurate length" );
+    }
+    ***/
+    
+  // -->
+  </script>
+</head>
+<body>
+</body>
+</html>

Modified: sandbox/vector-2.4/tests/list-tests.html
===================================================================
--- sandbox/vector-2.4/tests/list-tests.html	2007-03-05 22:32:10 UTC (rev 2351)
+++ sandbox/vector-2.4/tests/list-tests.html	2007-03-05 22:40:06 UTC (rev 2352)
@@ -4,11 +4,12 @@
     <li>BaseTypes/test_Size.html</li>
     <li>BaseTypes/test_LonLat.html</li>
     <li>BaseTypes/test_Bounds.html</li>
+    <li>Geometry/test_Point.html</li>
     <li>Geometry/test_MultiPoint.html</li>
+    <li>Geometry/test_Curve.html</li>
+    <li>Geometry/test_LineString.html</li>
+    <li>Geometry/test_Polygon.html</li>
     <li>Geometry/test_MultiPolygon.html</li>
-    <li>Geometry/test_Point.html</li>
-    <li>Geometry/test_Polygon.html</li>
-    <li>Geometry/test_LineString.html</li>
     <li>test_Icon.html</li>
     <li>test_Marker.html</li>
     <li>test_Popup.html</li>



More information about the Commits mailing list