[test][index] Add a test of rtree inserts and removes for various parameters.

This commit is contained in:
Adam Wulkiewicz 2015-08-13 21:09:52 +02:00
parent 8fcbb8e370
commit b741c36c34
2 changed files with 84 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# Boost.Geometry Index
#
# Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
# Copyright (c) 2011-2015 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
@ -12,6 +12,7 @@ build-project generated ;
test-suite boost-geometry-index-rtree
:
[ run rtree_insert_remove.cpp ]
[ run rtree_move_pack.cpp ]
[ run rtree_values.cpp ]
[ compile-fail rtree_values_invalid.cpp ]

View File

@ -0,0 +1,82 @@
// Boost.Geometry Index
// Unit Test
// Copyright (c) 2015 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)
#include <rtree/test_rtree.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <boost/geometry/geometries/polygon.hpp>
template <typename Params>
void test_rtree(unsigned vcount)
{
typedef bg::model::point<int, 1, bg::cs::cartesian> point_t;
bgi::rtree<point_t, Params> rt;
BOOST_CHECK(rt.remove(point_t(0)) == 0);
for ( unsigned i = 0 ; i < vcount ; ++i )
{
rt.insert(point_t(static_cast<int>(i)));
}
BOOST_CHECK(rt.size() == vcount);
BOOST_CHECK(rt.count(point_t(vcount / 2)) == 1);
for ( unsigned i = 0 ; i < vcount + 3 ; ++i )
{
rt.remove(point_t((i + 3) % vcount));
}
BOOST_CHECK(rt.size() == 0);
BOOST_CHECK(rt.count(point_t(vcount / 2)) == 0);
for ( unsigned i = 0 ; i < vcount ; ++i )
{
rt.insert(point_t((i + 5) % vcount));
}
BOOST_CHECK(rt.size() == vcount);
BOOST_CHECK(rt.count(point_t(vcount / 2)) == 1);
for ( unsigned i = 0 ; i < vcount + 3 ; ++i )
{
rt.remove(point_t((i + 7) % vcount));
}
BOOST_CHECK(rt.size() == 0);
BOOST_CHECK(rt.count(point_t(vcount / 2)) == 0);
}
template <int Max, int Min>
void test_rtree_all()
{
int pow = Max;
for (int l = 0 ; l < 3 ; ++l)
{
pow *= Max;
int vcount = (pow * 8) / 10;
//std::cout << Max << " " << Min << " " << vcount << std::endl;
test_rtree< bgi::linear<Max, Min> >(vcount);
test_rtree< bgi::quadratic<Max, Min> >(vcount);
test_rtree< bgi::rstar<Max, Min> >(vcount);
}
}
int test_main(int, char* [])
{
test_rtree_all<2, 1>();
test_rtree_all<4, 1>();
test_rtree_all<4, 2>();
test_rtree_all<5, 3>();
return 0;
}