[geos-commits] r3726 - in trunk/tests/unit: . noding
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Dec 4 09:23:41 PST 2012
Author: strk
Date: 2012-12-04 09:23:41 -0800 (Tue, 04 Dec 2012)
New Revision: 3726
Added:
trunk/tests/unit/noding/OrientedCoordinateArray.cpp
Modified:
trunk/tests/unit/Makefile.am
Log:
Add unit test for OrientedCoordinateArray
Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am 2012-11-15 17:35:24 UTC (rev 3725)
+++ trunk/tests/unit/Makefile.am 2012-12-04 17:23:41 UTC (rev 3726)
@@ -74,6 +74,7 @@
linearref/LengthIndexedLineTest.cpp \
noding/BasicSegmentStringTest.cpp \
noding/NodedSegmentStringTest.cpp \
+ noding/OrientedCoordinateArray.cpp \
noding/SegmentNodeTest.cpp \
noding/SegmentPointComparatorTest.cpp \
noding/snapround/HotPixelTest.cpp \
Added: trunk/tests/unit/noding/OrientedCoordinateArray.cpp
===================================================================
--- trunk/tests/unit/noding/OrientedCoordinateArray.cpp (rev 0)
+++ trunk/tests/unit/noding/OrientedCoordinateArray.cpp 2012-12-04 17:23:41 UTC (rev 3726)
@@ -0,0 +1,122 @@
+// $Id$
+//
+// Test Suite for geos::noding::OrientedCoordinateArray class.
+
+#include <tut.hpp>
+// geos
+#include <geos/noding/OrientedCoordinateArray.h>
+#include <geos/io/WKTReader.h>
+#include <geos/geom/PrecisionModel.h>
+#include <geos/geom/GeometryFactory.h>
+#include <geos/geom/Geometry.h>
+#include <geos/geom/Coordinate.h>
+#include <geos/geom/CoordinateSequence.h>
+// std
+#include <memory>
+
+using namespace geos::geom;
+using namespace geos::noding;
+
+namespace tut
+{
+ //
+ // Test Group
+ //
+
+ // Common data used by all tests
+ struct test_orientedcoordinatearray_data
+ {
+ geos::geom::PrecisionModel pm_;
+ geos::geom::GeometryFactory factory_;
+ geos::io::WKTReader reader_;
+
+ typedef std::auto_ptr<CoordinateSequence> CoordSeqPtr;
+ typedef std::auto_ptr<Geometry> GeomPtr;
+
+ test_orientedcoordinatearray_data()
+ : pm_(), factory_(&pm_), reader_(&factory_) {}
+
+ CoordSeqPtr coords_from_wkt(const char *wkt) {
+ GeomPtr g ( reader_.read(wkt) );
+ CoordSeqPtr cs ( g->getCoordinates() );
+ return cs;
+ }
+ };
+
+ typedef test_group<test_orientedcoordinatearray_data> group;
+ typedef group::object object;
+
+ group test_orientedcoordinatearray_group("geos::noding::OrientedCoordinateArray");
+
+ //
+ // Test Cases
+ //
+
+ // Compare to self, closed
+ template<>
+ template<>
+ void object::test<1>()
+ {
+ const char *coords = "LINESTRING(361600 6126500, 361620 6126560, 361630 6126550, 361620 6126530, 361600 6126500)";
+ CoordSeqPtr cs = coords_from_wkt(coords);
+ OrientedCoordinateArray oca1(*cs);
+ OrientedCoordinateArray oca2(*cs);
+ ensure_equals(oca1.compareTo(oca2), 0);
+ }
+
+ // Compare to reverse of self, closed
+ template<>
+ template<>
+ void object::test<2>()
+ {
+ const char *coords1 = "LINESTRING(361600 6126500, 361620 6126560, 361630 6126550, 361620 6126530, 361600 6126500)";
+ const char *coords2 = "LINESTRING(361600 6126500, 361620 6126530, 361630 6126550, 361620 6126560, 361600 6126500)";
+ CoordSeqPtr cs1 = coords_from_wkt(coords1);
+ OrientedCoordinateArray oca1(*cs1);
+ CoordSeqPtr cs2 = coords_from_wkt(coords2);
+ OrientedCoordinateArray oca2(*cs2);
+ ensure_equals(oca1.compareTo(oca2), 0);
+ }
+
+ // Compare to self, not closed
+ template<>
+ template<>
+ void object::test<3>()
+ {
+ const char *coords = "LINESTRING(361620 6126560, 361630 6126550, 361620 6126530, 361600 6126500)";
+ CoordSeqPtr cs = coords_from_wkt(coords);
+ OrientedCoordinateArray oca1(*cs);
+ OrientedCoordinateArray oca2(*cs);
+ ensure_equals(oca1.compareTo(oca2), 0);
+ }
+
+ // Compare to reverse of self, not closed
+ template<>
+ template<>
+ void object::test<4>()
+ {
+ const char *coords1 = "LINESTRING(361620 6126560, 361630 6126550, 361620 6126530, 361600 6126500)";
+ const char *coords2 = "LINESTRING(361600 6126500, 361620 6126530, 361630 6126550, 361620 6126560)";
+ CoordSeqPtr cs1 = coords_from_wkt(coords1);
+ OrientedCoordinateArray oca1(*cs1);
+ CoordSeqPtr cs2 = coords_from_wkt(coords2);
+ OrientedCoordinateArray oca2(*cs2);
+ ensure_equals(oca1.compareTo(oca2), 0);
+ }
+
+ // Compare both ways
+ template<>
+ template<>
+ void object::test<5>()
+ {
+ const char *coords1 = "LINESTRING(0 0, 10 0)";
+ const char *coords2 = "LINESTRING(0 0, 10 0, 11 0)";
+ CoordSeqPtr cs1 = coords_from_wkt(coords1);
+ OrientedCoordinateArray oca1(*cs1);
+ CoordSeqPtr cs2 = coords_from_wkt(coords2);
+ OrientedCoordinateArray oca2(*cs2);
+ ensure_equals(oca1.compareTo(oca2), -1);
+ ensure_equals(oca2.compareTo(oca1), 1);
+ }
+
+} // namespace tut
More information about the geos-commits
mailing list