|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r74442 - sandbox-branches/geometry/index/tests
From: adam.wulkiewicz_at_[hidden]
Date: 2011-09-17 20:48:29
Author: awulkiew
Date: 2011-09-17 20:48:28 EDT (Sat, 17 Sep 2011)
New Revision: 74442
URL: http://svn.boost.org/trac/boost/changeset/74442
Log:
query name fixed in tests + partially switched to Boost.Test.
Removed:
sandbox-branches/geometry/index/tests/additional_load_time_vis.cpp
Text files modified:
sandbox-branches/geometry/index/tests/main.cpp | 48 +++-----------
sandbox-branches/geometry/index/tests/rtree_filters.hpp | 17 ++--
sandbox-branches/geometry/index/tests/translators.hpp | 125 +++++++++++++++++++++------------------
3 files changed, 88 insertions(+), 102 deletions(-)
Deleted: sandbox-branches/geometry/index/tests/additional_load_time_vis.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/additional_load_time_vis.cpp 2011-09-17 20:48:28 EDT (Sat, 17 Sep 2011)
+++ (empty file)
@@ -1,141 +0,0 @@
-#include <boost/geometry/extensions/index/rtree/rtree.hpp>
-
-#include <iostream>
-#include <fstream>
-
-#include <boost/timer.hpp>
-#include <boost/foreach.hpp>
-
-//TEST
-#include <gl/glut.h>
-#include <boost/geometry/extensions/index/rtree/visitors/gl_draw.hpp>
-
-typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
-typedef boost::geometry::model::box<P> B;
-boost::geometry::index::rtree< std::pair<B, size_t> > t;
-
-void render_scene(void)
-{
- boost::geometry::index::gl_draw(t, 0, 1, 20000.0f);
-}
-
-void resize(int w, int h)
-{
- if ( h == 0 )
- h = 1;
-
- float ratio = float(w) / h;
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glViewport(0, 0, w, h);
-
- gluPerspective(45.0, ratio, 1, 10000000.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(
- 2000000.0, 2000000.0, 2000000.0,
- 0.0, 0.0, -1.0,
- 0.0, 1.0, 0.0);
-}
-
-int main(int argc, char **argv)
-{
- boost::timer tim;
-
- // randomize boxes
- const size_t n = 1000000;
- //const size_t n = 300;
- const size_t ns = 100000;
-
- std::ifstream file_cfg("config.txt");
- std::ifstream file("test_coords.txt");
-
- std::cout << "loading data\n";
- std::vector< std::pair<float, float> > coords(n);
- for ( size_t i = 0 ; i < n ; ++i )
- {
- file >> coords[i].first;
- file >> coords[i].second;
- }
- std::cout << "loaded\n";
-
- std::cin.get();
-
- size_t max_elems, min_elems;
- file_cfg >> max_elems;
- file_cfg >> min_elems;
- std::cout << "max: " << max_elems << ", min: " << min_elems << "\n";
-
- t = boost::geometry::index::rtree< std::pair<B, size_t> > (max_elems, min_elems);
-
- //std::cout << "inserting time test...\n";
- //tim.restart();
- //for (size_t i = 0 ; i < n ; ++i )
- //{
- // float x = coords[i].first;
- // float y = coords[i].second;
- // B b(P(x - 0.5f, y - 0.5f), P(x + 0.5f, y + 0.5f));
-
- // // Zle wyswietla dane, obcina czesc ulamkowa
- // // Zle buduje drzewo dla i == 228
-
- // //TEST
- // /*if ( i == 228 )
- // {
- // std::cout << std::fixed << x << ", " << y << "\n";
- // boost::geometry::index::detail::rtree::visitors::detail::print_indexable(std::cout, b);
- // }*/
-
- // t.insert(std::make_pair(b, i));
-
- // //TEST
- // /*if ( !boost::geometry::index::are_boxes_ok(t) )
- // {
- // std::ofstream log("log1.txt", std::ofstream::trunc);
- // log << std::fixed << i << " - " << x << ", " << y << " - inserted: ";
- // boost::geometry::index::detail::rtree::visitors::detail::print_indexable(log, b);
- // log << '\n';
- // log << ( boost::geometry::index::are_boxes_ok(t) ? "boxes OK" : "WRONG BOXES!" );
- // log << '\n' << t;
- // }*/
- //}
- //std::cout << "time: " << tim.elapsed() << "s\n";
-
- {
- std::cout << "loading tree structure...\n";
- std::ifstream is("save.txt");
- t.load(is);
- std::cout << "done.\n";
- }
-
- std::cout << "searching time test...\n";
- tim.restart();
- size_t temp = 0;
- for (size_t i = 0 ; i < ns ; ++i )
- {
- float x = coords[i].first;
- float y = coords[i].second;
- std::deque< std::pair<B, size_t> > result = t.find(B(P(x - 10, y - 10), P(x + 10, y + 10)));
- temp += result.size();
- }
- std::cout << "time: " << tim.elapsed() << "s\n";
- std::cout << temp << "\n";
-
- std::cin.get();
-
- //TEST
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA);
- glutInitWindowPosition(100,100);
- glutInitWindowSize(800, 600);
- glutCreateWindow("Mouse click to insert new value");
-
- glutDisplayFunc(render_scene);
- glutReshapeFunc(resize);
-
- glutMainLoop();
-
- return 0;
-}
Modified: sandbox-branches/geometry/index/tests/main.cpp
==============================================================================
--- sandbox-branches/geometry/index/tests/main.cpp (original)
+++ sandbox-branches/geometry/index/tests/main.cpp 2011-09-17 20:48:28 EDT (Sat, 17 Sep 2011)
@@ -1,55 +1,31 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)
//
-// Boost.Index - example
+// Boost.Index - unit tests
//
// Copyright 2011 Adam Wulkiewicz.
// 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)
+#define BOOST_TEST_MODULE test_module_boost_geometry_index
+#include <boost/test/unit_test.hpp>
+
#include <tests/translators.hpp>
#include <tests/rtree_native.hpp>
#include <tests/rtree_filters.hpp>
-#include <boost/geometry/extensions/index/rtree/visitors/are_boxes_ok.hpp>
-
-int main()
+BOOST_AUTO_TEST_CASE( main )
{
- tests_translators_hpp();
- tests_rtree_native_hpp<boost::geometry::index::linear<4, 2> >();
- tests_rtree_native_hpp<boost::geometry::index::quadratic<4, 2> >();
- tests_rtree_native_hpp<boost::geometry::index::rstar<4, 2> >();
+ std::cout << "test\n";
+
+ tests_rtree_native_hpp< boost::geometry::index::linear<32, 8> >();
+ tests_rtree_native_hpp< boost::geometry::index::quadratic<32, 8> >();
+ tests_rtree_native_hpp< boost::geometry::index::rstar<32, 8> >();
+
tests_rtree_filters_hpp();
- /*
- {
- namespace bg = boost::geometry;
- namespace bgi = boost::geometry::index;
- typedef bg::model::point<float, 2, bg::cs::cartesian> P;
- typedef bg::model::box<P> B;
- typedef std::pair<B, int> V;
-
- bgi::rtree<V, bgi::default_parameter, bgi::linear_tag> t(4, 2);
- const int m = 15;
- for ( int i = 0 ; i < m ; ++i )
- {
- bgi::insert(t, V(B(P(i*2.0f, i*2.0f), P(i*2.0f+1, i*2.0f+1)), i));
- }
- std::cout << t << "\n------------------------------------\n";
- std::cin.get();
-
- for ( int i = 0 ; i < m ; ++i )
- {
- bgi::remove(t, V(B(P(i*2.0f, i*2.0f), P(i*2.0f+1, i*2.0f+1)), i));
- std::cout << t << '\n';
- std::cout << ( boost::geometry::index::are_boxes_ok(t) ? "boxes OK" : "WRONG BOXES!" );
- std::cout << "\n------------------------------------\n";
- std::cin.get();
- }
- }
- */
+
#ifdef _MSC_VER
std::cin.get();
#endif
- return 0;
}
Modified: sandbox-branches/geometry/index/tests/rtree_filters.hpp
==============================================================================
--- sandbox-branches/geometry/index/tests/rtree_filters.hpp (original)
+++ sandbox-branches/geometry/index/tests/rtree_filters.hpp 2011-09-17 20:48:28 EDT (Sat, 17 Sep 2011)
@@ -37,17 +37,18 @@
typedef boost::geometry::model::box<P> B;
{
- boost::geometry::index::rtree<B, boost::geometry::index::rstar<4, 2> > t;
- boost::geometry::index::insert(t, B(P(0, 0), P(1, 1)));
- boost::geometry::index::insert(t, B(P(2, 2), P(3, 3)));
- boost::geometry::index::insert(t, B(P(4, 4), P(5, 5)));
- boost::geometry::index::insert(t, B(P(6, 6), P(7, 7)));
- boost::geometry::index::insert(t, B(P(8, 8), P(9, 9)));
+ namespace bgi = boost::geometry::index;
+
+ bgi::rtree<B, bgi::rstar<4, 2> > t;
+ bgi::insert(t, B(P(0, 0), P(1, 1)));
+ bgi::insert(t, B(P(2, 2), P(3, 3)));
+ bgi::insert(t, B(P(4, 4), P(5, 5)));
+ bgi::insert(t, B(P(6, 6), P(7, 7)));
+ bgi::insert(t, B(P(8, 8), P(9, 9)));
std::cout << t;
std::cout << "Query: (2.5, 2.5)x(4.5, 4.5)\n";
- namespace f = boost::geometry::index::filters;
- tests_rtree_filters_hpp_print_range(t | f::spatially_filtered(B(P(2.5f, 2.5f), P(4.5f, 4.5f))));
+ tests_rtree_filters_hpp_print_range(t | bgi::query_filtered(B(P(2.5f, 2.5f), P(4.5f, 4.5f))));
}
}
Modified: sandbox-branches/geometry/index/tests/translators.hpp
==============================================================================
--- sandbox-branches/geometry/index/tests/translators.hpp (original)
+++ sandbox-branches/geometry/index/tests/translators.hpp 2011-09-17 20:48:28 EDT (Sat, 17 Sep 2011)
@@ -3,9 +3,8 @@
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
-#include <boost/geometry/extensions/index/rtree/rtree.hpp>
-#include <boost/geometry/extensions/index/translator/translator.hpp>
+#include <boost/geometry/extensions/index/rtree/rtree.hpp>
#include <vector>
#include <map>
@@ -16,6 +15,10 @@
template <typename Indexable>
struct tests_translators_val
{
+ tests_translators_val(Indexable const& ii)
+ : i(ii)
+ {}
+
Indexable const& get_box() const
{
return i;
@@ -29,64 +32,70 @@
Indexable i;
};
-void tests_translators_hpp()
+BOOST_AUTO_TEST_CASE(tests_translators)
{
- std::cout << "tests/translators.hpp\n";
-
- typedef boost::geometry::model::point<float, 2, boost::geometry::cs::cartesian> P;
- typedef boost::geometry::model::box<P> B;
- //typedef boost::geometry::index::rtree<B> I;
-
- using namespace boost::geometry;
-
- index::translator::def<P> p;
- index::translator::def<P*> pp;
- index::translator::def<std::pair<int, P>*> pip;
- index::translator::def< boost::shared_ptr<P> > sp;
- index::translator::def< std::vector<P>::iterator > ip;
- index::translator::def< std::map<int, P>::iterator > mip;
- index::translator::def< std::pair<P, size_t> > ppi;
- index::translator::def< boost::shared_ptr< std::pair<int, P> > > spip;
- index::translator::def< boost::shared_ptr< std::pair<P, int> > > sppi;
- index::translator::def< boost::scoped_ptr< std::pair<P, int> > > scppi;
- index::translator::def< boost::scoped_ptr< std::pair<int, P> > > scpip;
-
- P tmp_p;
- boost::shared_ptr<P> tmp_sp(new P());
- std::vector<P> tmp_v(1);
+ namespace bg = boost::geometry;
+ namespace bgm = bg::model;
+ namespace bgi = bg::index;
+ namespace bgit = bgi::translator;
+
+ typedef bgm::point<float, 2, bg::cs::cartesian> P;
+ typedef bgm::box<P> B;
+
+ bgit::def< P > p;
+ bgit::def< P* > pp;
+ bgit::def< std::pair<int, P>* > ppip;
+ bgit::def< boost::shared_ptr<P> > sp;
+ bgit::def< std::vector<P>::iterator > ip;
+ bgit::def< std::map<int, P>::iterator > mip;
+ bgit::def< std::pair<int, P> > pip;
+ bgit::def< boost::shared_ptr< std::pair<int, P> > > spip;
+ bgit::def< boost::shared_ptr< std::pair<P, int> > > sppi;
+ bgit::def< boost::scoped_ptr< std::pair<P, int> > > scppi;
+ bgit::def< boost::scoped_ptr< std::pair<int, P> > > scpip;
+
+ P tmp_p(2, 3);
+ boost::shared_ptr<P> tmp_sp(new P(2, 3));
+ std::vector<P> tmp_v(1, P(2, 3));
std::map<int, P> tmp_m;
- tmp_m.insert(std::pair<int, P>(0, P()));
- std::pair<int, P> tmp_pip;
- boost::shared_ptr< std::pair<int, P> > tmp_spip(new std::pair<int, P>(0, P()));
- boost::shared_ptr< std::pair<P, int> > tmp_sppi(new std::pair<P, int>(P(), 0));
- boost::scoped_ptr< std::pair<int, P> > tmp_scpip(new std::pair<int, P>(0, P()));
- boost::scoped_ptr< std::pair<P, int> > tmp_scppi(new std::pair<P, int>(P(), 0));
-
- tmp_p = p(P());
- tmp_p = pp(&tmp_p);
- tmp_p = pip(&tmp_pip);
- tmp_p = sp(tmp_sp);
- tmp_p = ip(tmp_v.begin());
- tmp_p = mip(tmp_m.begin());
- tmp_p = ppi(std::pair<P, size_t>(P(), 0));
- tmp_p = spip(tmp_spip);
- tmp_p = sppi(tmp_sppi);
- tmp_p = scpip(tmp_scpip);
- tmp_p = scppi(tmp_scppi);
-
- //index::translator::def<int> d; // error
- //index::translator::def< model::segment<P> > d; // error
-
- index::translator::def< std::pair<model::polygon<P>, B> > d;
- index::translator::def< std::pair<B, model::polygon<P> > > dd;
-
- B tmp_b;
- tmp_b = d( std::pair<model::polygon<P>, B>() );
- tmp_b = dd( std::pair<B, model::polygon<P> >() );
-
- tests_translators_val<P> val_p;
- index::translator::getter<tests_translators_val<P>, P, &tests_translators_val<P>::get_box> tr_get_p;
- tmp_p = tr_get_p(val_p);
+ tmp_m.insert(std::pair<int, P>(0, P(2, 3)));
+ std::pair<int, P> tmp_pip(0, P(2, 3));
+ boost::shared_ptr< std::pair<int, P> > tmp_spip(new std::pair<int, P>(0, P(2, 3)));
+ boost::shared_ptr< std::pair<P, int> > tmp_sppi(new std::pair<P, int>(P(2, 3), 0));
+ boost::scoped_ptr< std::pair<int, P> > tmp_scpip(new std::pair<int, P>(0, P(2, 3)));
+ boost::scoped_ptr< std::pair<P, int> > tmp_scppi(new std::pair<P, int>(P(2, 3), 0));
+
+ BOOST_CHECK( bg::equals(tmp_p, p(tmp_p)) );
+ BOOST_CHECK( bg::equals(tmp_p, pp(&tmp_p)) );
+ BOOST_CHECK( bg::equals(tmp_p, ppip(&tmp_pip)) );
+ BOOST_CHECK( bg::equals(tmp_p, sp(tmp_sp)) );
+ BOOST_CHECK( bg::equals(tmp_p, ip(tmp_v.begin())) );
+ BOOST_CHECK( bg::equals(tmp_p, mip(tmp_m.begin())) );
+ BOOST_CHECK( bg::equals(tmp_p, pip(tmp_pip)) );
+ BOOST_CHECK( bg::equals(tmp_p, spip(tmp_spip)) );
+ BOOST_CHECK( bg::equals(tmp_p, sppi(tmp_sppi)) );
+ BOOST_CHECK( bg::equals(tmp_p, scpip(tmp_scpip)) );
+ BOOST_CHECK( bg::equals(tmp_p, scppi(tmp_scppi)) );
+
+ //bgit::def<int> d; // error
+ //bgit::def< bgm::segment<P> > d; // error
+
+ B tmp_b(P(2, 3), P(4, 5));
+ std::pair<bgm::polygon<P>, B> tmp_ppb =
+ std::make_pair(bgm::polygon<P>(), tmp_b);
+ std::pair<B, bgm::polygon<P>> tmp_pbp =
+ std::make_pair(tmp_b, bgm::polygon<P>());
+
+ bgit::def< std::pair<bgm::polygon<P>, B> > ppb;
+ bgit::def< std::pair<B, bgm::polygon<P> > > pbp;
+
+ BOOST_CHECK( bg::equals(tmp_b, ppb(tmp_ppb)) );
+ BOOST_CHECK( bg::equals(tmp_b, pbp(tmp_pbp)) );
+
+ tests_translators_val<P> val_p(tmp_p);
+ bgit::getter<tests_translators_val<P>, P, &tests_translators_val<P>::get_box> tr_get_p;
+
+ BOOST_CHECK( bg::equals(tmp_p, tr_get_p(val_p)) );
}
#endif // TESTS_TRANSLATORS_HPP
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk