[num_points][test] Added test for num_points which was not yet there

This commit is contained in:
Barend Gehrels 2014-05-14 14:18:48 +02:00
parent afb301f6ed
commit a703cae46e
2 changed files with 66 additions and 0 deletions

View File

@ -47,6 +47,7 @@ test-suite boost-geometry-algorithms
[ run intersects.cpp : : : <toolset>msvc:<cxxflags>/bigobj ]
[ run length.cpp ]
[ run make.cpp ]
[ run num_points.cpp ]
[ run overlaps.cpp ]
[ run perimeter.cpp ]
[ run point_on_surface.cpp ]

View File

@ -0,0 +1,65 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
// Unit Test
// Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
// Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
// Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_TEST_MODULE
#define BOOST_TEST_MODULE test_num_points
#endif
#include <iostream>
#include <boost/test/included/unit_test.hpp>
#include <boost/geometry/algorithms/num_points.hpp>
#include <boost/geometry/multi/algorithms/num_points.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/multi/geometries/multi_geometries.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <boost/geometry/multi/io/wkt/read.hpp>
template <typename Geometry>
inline void test_num_points(std::string const& wkt, std::size_t expected)
{
namespace bg = boost::geometry;
Geometry geometry;
boost::geometry::read_wkt(wkt, geometry);
std::size_t detected = bg::num_points(geometry);
BOOST_CHECK_EQUAL(expected, detected);
detected = bg::num_points(geometry, false);
BOOST_CHECK_EQUAL(expected, detected);
detected = bg::num_points(geometry, true);
}
BOOST_AUTO_TEST_CASE( test_num_points_closed )
{
namespace bg = boost::geometry;
typedef bg::model::point<double,2,bg::cs::cartesian> point;
typedef bg::model::linestring<point> linestring;
typedef bg::model::segment<point> segment;
typedef bg::model::box<point> box;
typedef bg::model::ring<point> ring;
typedef bg::model::polygon<point> polygon;
typedef bg::model::multi_point<point> multi_point;
typedef bg::model::multi_linestring<linestring> multi_linestring;
typedef bg::model::multi_polygon<polygon> multi_polygon;
test_num_points<point>("POINT(0 0)", 1u);
test_num_points<linestring>("LINESTRING(0 0,1 1)", 2u);
test_num_points<segment>("LINESTRING(0 0,1 1)", 2u);
test_num_points<box>("POLYGON((0 0,10 10))", 4u);
test_num_points<ring>("POLYGON((0 0,1 1,0 1,0 0))", 4u);
test_num_points<polygon>("POLYGON((0 0,10 10,0 10,0 0))", 4u);
test_num_points<polygon>("POLYGON((0 0,0 10,10 10,10 0,0 0),(4 4,6 4,6 6,4 6,4 4))", 10u);
test_num_points<multi_point>("MULTIPOINT((0 0),(1 1))", 2u);
test_num_points<multi_linestring>("MULTILINESTRING((0 0,1 1),(2 2,3 3,4 4))", 5u);
test_num_points<multi_polygon>("MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((0 10,1 10,1 9,0 10)))", 9u);
}