[geos-commits] r3196 - in trunk: include/geos/operation/union tests/unit tests/unit/operation/union

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Feb 10 10:51:16 EST 2011


Author: strk
Date: 2011-02-10 07:51:16 -0800 (Thu, 10 Feb 2011)
New Revision: 3196

Added:
   trunk/tests/unit/operation/union/UnaryUnionOpTest.cpp
Modified:
   trunk/include/geos/operation/union/UnaryUnionOp.h
   trunk/tests/unit/Makefile.am
   trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp
Log:
Add unit test for UnaryUnionOp (and fix interface bug)

Modified: trunk/include/geos/operation/union/UnaryUnionOp.h
===================================================================
--- trunk/include/geos/operation/union/UnaryUnionOp.h	2011-02-10 14:14:30 UTC (rev 3195)
+++ trunk/include/geos/operation/union/UnaryUnionOp.h	2011-02-10 15:51:16 UTC (rev 3196)
@@ -106,7 +106,7 @@
       :
       geomFact(&geomFactIn)
   {
-    extractAll(geoms);
+    extractGeoms(geoms);
   }
 
   template <class T>
@@ -114,7 +114,7 @@
       :
       geomFact(0)
   {
-    extractAll(geoms);
+    extractGeoms(geoms);
   }
 
   UnaryUnionOp(const geom::Geometry& geom)

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2011-02-10 14:14:30 UTC (rev 3195)
+++ trunk/tests/unit/Makefile.am	2011-02-10 15:51:16 UTC (rev 3196)
@@ -81,6 +81,7 @@
 	operation/overlay/snap/LineStringSnapperTest.cpp \
 	operation/sharedpaths/SharedPathsOpTest.cpp \
 	operation/union/CascadedPolygonUnionTest.cpp \
+	operation/union/UnaryUnionOpTest.cpp \
 	operation/valid/IsValidTest.cpp \
 	operation/valid/ValidClosedRingTest.cpp \
 	operation/valid/ValidSelfTouchingRingFormingHoleTest.cpp \

Modified: trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp
===================================================================
--- trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp	2011-02-10 14:14:30 UTC (rev 3195)
+++ trunk/tests/unit/operation/union/CascadedPolygonUnionTest.cpp	2011-02-10 15:51:16 UTC (rev 3196)
@@ -24,7 +24,7 @@
     //
 
     // Common data used by tests
-    struct test_unaryuniontest_data
+    struct test_cascadedpolygonuniontest_data
     {
         geos::geom::GeometryFactory gf;
         geos::io::WKTReader wktreader;
@@ -32,16 +32,16 @@
 
         typedef geos::geom::Geometry::AutoPtr GeomPtr;
 
-        test_unaryuniontest_data()
+        test_cascadedpolygonuniontest_data()
           : gf(),
             wktreader(&gf)
         {}
     };
 
-    typedef test_group<test_unaryuniontest_data> group;
+    typedef test_group<test_cascadedpolygonuniontest_data> group;
     typedef group::object object;
 
-    group test_unaryuniontest_group("geos::operation::geounion::CascadedPolygonUnion");
+    group test_cascadedpolygonuniontest_group("geos::operation::geounion::CascadedPolygonUnion");
 
     // test runner
     geos::geom::Geometry* unionIterated(
@@ -72,7 +72,7 @@
         return CascadedPolygonUnion::Union(geoms);
     }
 
-    void test_runner(test_unaryuniontest_data& t,
+    void test_runner(test_cascadedpolygonuniontest_data& t,
         std::vector<geos::geom::Polygon*>* geoms) 
     {
         std::auto_ptr<geos::geom::Geometry> union1(unionIterated(geoms));

Added: trunk/tests/unit/operation/union/UnaryUnionOpTest.cpp
===================================================================
--- trunk/tests/unit/operation/union/UnaryUnionOpTest.cpp	                        (rev 0)
+++ trunk/tests/unit/operation/union/UnaryUnionOpTest.cpp	2011-02-10 15:51:16 UTC (rev 3196)
@@ -0,0 +1,155 @@
+// $Id$
+// 
+// Test Suite for geos::operation::geounion::CascadedPolygonUnion class.
+
+// tut
+#include <tut.hpp>
+// geos
+#include <geos/operation/union/UnaryUnionOp.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/Point.h>
+#include <geos/io/WKTReader.h>
+#include <geos/io/WKTWriter.h>
+// std
+#include <memory>
+#include <string>
+#include <vector>
+#include <iostream>
+
+namespace tut
+{
+    //
+    // Test Group
+    //
+
+    // Common data used by tests
+    struct test_unaryuniontest_data
+    {
+        geos::geom::GeometryFactory gf;
+        geos::io::WKTReader wktreader;
+        geos::io::WKTWriter wktwriter;
+
+        typedef geos::geom::Geometry::AutoPtr GeomPtr;
+        typedef geos::geom::Geometry Geom;
+        typedef geos::operation::geounion::UnaryUnionOp UnaryUnionOp;
+
+        test_unaryuniontest_data()
+          : gf(),
+            wktreader(&gf)
+        {
+          wktwriter.setTrim(true);
+        }
+
+        void delAll(std::vector<Geom*>& geoms)
+        {
+          for (size_t i=0; i<geoms.size(); ++i) delete geoms[i];
+        }
+
+        GeomPtr readWKT(const std::string& inputWKT)
+        {
+            return GeomPtr(wktreader.read(inputWKT));
+        }
+
+        void readWKT(const char* const* inputWKT, std::vector<Geom*>& geoms)
+        {
+          for (const char* const* ptr=inputWKT; *ptr; ++ptr) {
+            geoms.push_back(readWKT(*ptr).release());
+          }
+        }
+
+        static GeomPtr normalize(const Geom& g)
+        {
+          GeomPtr g2 ( g.clone() );
+          g2->normalize();
+          return g2;
+        }
+
+        bool isEqual(const Geom& a, const Geom& b)
+        {
+          using std::cout;
+          using std::endl;
+          GeomPtr a2 = normalize(a);
+          GeomPtr b2 = normalize(b);
+          bool eq = a2->equalsExact(b2.get());
+          if  ( ! eq ) {
+            cout << "OBTAINED: " << wktwriter.write(b2.get()) << endl;
+          }
+          return eq;
+        }
+
+        void doTest(const char* const* inputWKT, const std::string& expectedWKT)
+        {
+          std::vector<Geom*> geoms;
+          readWKT(inputWKT, geoms);
+
+          GeomPtr result;
+          if ( geoms.empty() )
+            result = UnaryUnionOp::Union(geoms, gf);
+          else
+            result = UnaryUnionOp::Union(geoms);
+
+          bool ok = isEqual(*readWKT(expectedWKT), *result);
+          delAll(geoms);
+
+          ensure(ok);
+        }
+
+    };
+
+    typedef test_group<test_unaryuniontest_data> group;
+    typedef group::object object;
+
+    group test_unaryuniontest_group("geos::operation::geounion::UnaryUnionOp");
+
+    template<>
+    template<>
+    void object::test<1>()
+    {
+        static char const* const geoms[] = { NULL };
+        doTest(geoms, "GEOMETRYCOLLECTION EMPTY");
+    }
+
+    template<>
+    template<>
+    void object::test<2>()
+    {
+        static char const* const geoms[] = {
+          "POINT (1 1)", "POINT (2 2)",
+          NULL
+        };
+        doTest(geoms, "MULTIPOINT ((1 1), (2 2))");
+    }
+
+    template<>
+    template<>
+    void object::test<3>()
+    {
+        static char const* const geoms[] = {
+          "GEOMETRYCOLLECTION (POLYGON ((0 0, 0 90, 90 90, 90 0, 0 0)),   POLYGON ((120 0, 120 90, 210 90, 210 0, 120 0)),  LINESTRING (40 50, 40 140),  LINESTRING (160 50, 160 140),  POINT (60 50),  POINT (60 140),  POINT (40 140))",
+          NULL
+        };
+        doTest(geoms, "GEOMETRYCOLLECTION (POINT (60 140),   LINESTRING (40 90, 40 140), LINESTRING (160 90, 160 140), POLYGON ((0 0, 0 90, 40 90, 90 90, 90 0, 0 0)), POLYGON ((120 0, 120 90, 160 90, 210 90, 210 0, 120 0)))");
+    }
+
+    template<>
+    template<>
+    void object::test<4>()
+    {
+        static char const* const geoms[] = 
+        {
+            "POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))",
+            "MULTIPOLYGON (((20 0, 20 10, 40 10, 40 0, 20 0)),((5 5, 5 8, 8 8, 8 5, 5 5)))",
+            "POINT (5 5)",
+            "POINT (-5 5)",
+            "LINESTRING (-10 -10, -10 0, -10 20)",
+            "LINESTRING (-10 2, 10 2)",
+            NULL
+        };
+        doTest(geoms, "GEOMETRYCOLLECTION (POLYGON ((0 0, 0 2, 0 10, 10 10, 10 2, 10 0, 0 0)), POLYGON ((20 0, 20 10, 40 10, 40 0, 20 0)), LINESTRING (-10 -10, -10 0, -10 2), LINESTRING (-10 2, 0 2), LINESTRING (-10 2, -10 20), POINT (-5 5))");
+
+    }
+
+} // namespace tut
+



More information about the geos-commits mailing list