|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84676 - in trunk/libs/geometry/index/test: . rtree/exceptions
From: adam.wulkiewicz_at_[hidden]
Date: 2013-06-07 13:36:56
Author: awulkiew
Date: 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013)
New Revision: 84676
URL: http://svn.boost.org/trac/boost/changeset/84676
Log:
geometry.index test: added tests for new implementation of varray.
Added:
trunk/libs/geometry/index/test/movable.hpp (contents, props changed)
trunk/libs/geometry/index/test/varray_old.cpp (contents, props changed)
trunk/libs/geometry/index/test/varray_test.hpp (contents, props changed)
Text files modified:
trunk/libs/geometry/index/test/Jamfile.v2 | 3
trunk/libs/geometry/index/test/movable.hpp | 92 ++++++
trunk/libs/geometry/index/test/rtree/exceptions/test_exceptions.hpp | 2
trunk/libs/geometry/index/test/varray.cpp | 584 +++++++++++++++++++++++++++++----------
trunk/libs/geometry/index/test/varray_old.cpp | 490 +++++++++++++++++++++++++++++++++
trunk/libs/geometry/index/test/varray_test.hpp | 97 ++++++
6 files changed, 1116 insertions(+), 152 deletions(-)
Modified: trunk/libs/geometry/index/test/Jamfile.v2
==============================================================================
--- trunk/libs/geometry/index/test/Jamfile.v2 Fri Jun 7 13:34:58 2013 (r84675)
+++ trunk/libs/geometry/index/test/Jamfile.v2 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013) (r84676)
@@ -17,8 +17,9 @@
<toolset>msvc:<asynch-exceptions>on
;
-test-suite boost-geometry-index
+test-suite boost-geometry-index-varray
:
+ [ run varray_old.cpp ]
[ run varray.cpp ]
;
Added: trunk/libs/geometry/index/test/movable.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/geometry/index/test/movable.hpp 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013) (r84676)
@@ -0,0 +1,92 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Ion Gaztanaga 2009.
+// Distributed under 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)
+//
+// See http://www.boost.org/libs/move for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_MOVE_TEST_MOVABLE_HPP
+#define BOOST_MOVE_TEST_MOVABLE_HPP
+
+//[movable_definition
+//header file "movable.hpp"
+#include <boost/move/move.hpp>
+
+//A movable class
+class movable
+{
+ BOOST_MOVABLE_BUT_NOT_COPYABLE(movable)
+ int value_;
+
+public:
+ movable() : value_(1){}
+
+ //Move constructor and assignment
+ movable(BOOST_RV_REF(movable) m)
+ { value_ = m.value_; m.value_ = 0; }
+
+ movable & operator=(BOOST_RV_REF(movable) m)
+ { value_ = m.value_; m.value_ = 0; return *this; }
+
+ bool moved() const //Observer
+ { return value_ == 0; }
+};
+
+
+class copy_movable
+{
+ BOOST_COPYABLE_AND_MOVABLE(copy_movable)
+ int value_;
+
+public:
+ copy_movable(int value = 1) : value_(value){}
+
+ //Move constructor and assignment
+ copy_movable(BOOST_RV_REF(copy_movable) m)
+ { value_ = m.value_; m.value_ = 0; }
+
+ copy_movable(const copy_movable &m)
+ { value_ = m.value_; }
+
+ copy_movable & operator=(BOOST_RV_REF(copy_movable) m)
+ { value_ = m.value_; m.value_ = 0; return *this; }
+
+ copy_movable & operator=(BOOST_COPY_ASSIGN_REF(copy_movable) m)
+ { value_ = m.value_; return *this; }
+
+ bool moved() const //Observer
+ { return value_ == 0; }
+
+ bool operator==(const copy_movable& m) const
+ { return value_ == m.value_; }
+};
+
+struct copy_movable_wrapper
+{
+ copy_movable cm;
+};
+
+copy_movable produce()
+{ return copy_movable(); }
+
+namespace boost{
+
+template<>
+struct has_nothrow_move<movable>
+{
+ static const bool value = true;
+};
+
+template<>
+struct has_nothrow_move<copy_movable>
+{
+ static const bool value = true;
+};
+
+} //namespace boost{
+//]
+
+#endif //BOOST_MOVE_TEST_MOVABLE_HPP
Modified: trunk/libs/geometry/index/test/rtree/exceptions/test_exceptions.hpp
==============================================================================
--- trunk/libs/geometry/index/test/rtree/exceptions/test_exceptions.hpp Fri Jun 7 13:34:58 2013 (r84675)
+++ trunk/libs/geometry/index/test/rtree/exceptions/test_exceptions.hpp 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013) (r84676)
@@ -47,7 +47,7 @@
BOOST_CHECK_THROW( tree.insert(input.begin(), input.end()), throwing_value_copy_exception );
}
- for ( size_t i = 0 ; i < 20 ; i += 2 )
+ for ( size_t i = 0 ; i < 10 ; i += 1 )
{
throwing_value::reset_calls_counter();
throwing_value::set_max_calls(10000);
Modified: trunk/libs/geometry/index/test/varray.cpp
==============================================================================
--- trunk/libs/geometry/index/test/varray.cpp Fri Jun 7 13:34:58 2013 (r84675)
+++ trunk/libs/geometry/index/test/varray.cpp 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013) (r84676)
@@ -1,7 +1,8 @@
-// Boost.Geometry Index
+// Boost.Geometry.Index varray
// Unit Test
-// Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2012-2013 Andrew Hundt.
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -10,65 +11,36 @@
#include <boost/test/included/test_exec_monitor.hpp>
#include <boost/test/impl/execution_monitor.ipp>
-#include <boost/geometry/index/detail/varray.hpp>
+// TODO: Disable parts of the unit test that should not run when BOOST_NO_EXCEPTIONS
+// if exceptions are enabled there must be a user defined throw_exception function
+#ifdef BOOST_NO_EXCEPTIONS
+namespace boost {
+ void throw_exception(std::exception const & e){}; // user defined
+} // namespace boost
+#endif // BOOST_NO_EXCEPTIONS
+
+#include <vector>
+#include <list>
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+#include <boost/container/vector.hpp>
+#include <boost/container/stable_vector.hpp>
+using namespace boost::container;
+#endif
-using namespace boost::geometry::index::detail;
+#include "varray_test.hpp"
-class value_ndc
-{
-public:
- explicit value_ndc(int a) : aa(a) {}
- ~value_ndc() {}
- bool operator==(value_ndc const& v) const { return aa == v.aa; }
-private:
- value_ndc(value_ndc const&) {}
- value_ndc & operator=(value_ndc const&) { return *this; }
- int aa;
-};
-
-class value_nd
-{
-public:
- explicit value_nd(int a) : aa(a) {}
- ~value_nd() {}
- bool operator==(value_nd const& v) const { return aa == v.aa; }
-private:
- int aa;
-};
-
-class value_nc
-{
-public:
- explicit value_nc(int a = 0) : aa(a) {}
- ~value_nc() {}
- bool operator==(value_nc const& v) const { return aa == v.aa; }
-private:
- value_nc(value_nc const&) {}
- value_nc & operator=(value_ndc const&) { return *this; }
- int aa;
-};
-
-class counting_value
-{
-public:
- explicit counting_value(int a = 0) : aa(a) { ++c(); }
- counting_value(counting_value const& v) : aa(v.aa) { ++c(); }
- counting_value & operator=(counting_value const& v) { aa = v.aa; return *this; }
- ~counting_value() { --c(); }
- bool operator==(counting_value const& v) const { return aa == v.aa; }
- static size_t count() { return c(); }
-private:
- static size_t & c() { static size_t co = 0; return co; }
- int aa;
-};
+using namespace boost::geometry::index::detail;
template <typename T, size_t N>
void test_ctor_ndc()
{
varray<T, N> s;
- BOOST_CHECK(s.size() == 0);
+ BOOST_CHECK_EQUAL(s.size() , 0);
BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
}
template <typename T, size_t N>
@@ -77,11 +49,19 @@
varray<T, N> s(n);
BOOST_CHECK(s.size() == n);
BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(n), std::out_of_range );
- if ( !boost::has_trivial_constructor<T>::value )
+#endif // BOOST_NO_EXCEPTIONS
+ if ( 1 < n )
{
- for ( size_t i = 0 ; i < n ; ++i )
- BOOST_CHECK(T() == s[i]);
+ T val10(10);
+ s[0] = val10;
+ BOOST_CHECK(T(10) == s[0]);
+ BOOST_CHECK(T(10) == s.at(0));
+ T val20(20);
+ s.at(1) = val20;
+ BOOST_CHECK(T(20) == s[1]);
+ BOOST_CHECK(T(20) == s.at(1));
}
}
@@ -91,7 +71,9 @@
varray<T, N> s(n, v);
BOOST_CHECK(s.size() == n);
BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
if ( 1 < n )
{
BOOST_CHECK(v == s[0]);
@@ -115,12 +97,19 @@
s.resize(n);
BOOST_CHECK(s.size() == n);
BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(n), std::out_of_range );
-
- if ( !boost::has_trivial_constructor<T>::value )
+#endif // BOOST_NO_EXCEPTIONS
+ if ( 1 < n )
{
- for ( size_t i = 0 ; i < n ; ++i )
- BOOST_CHECK(T() == s[i]);
+ T val10(10);
+ s[0] = val10;
+ BOOST_CHECK(T(10) == s[0]);
+ BOOST_CHECK(T(10) == s.at(0));
+ T val20(20);
+ s.at(1) = val20;
+ BOOST_CHECK(T(20) == s[1]);
+ BOOST_CHECK(T(20) == s.at(1));
}
}
@@ -132,7 +121,9 @@
s.resize(n, v);
BOOST_CHECK(s.size() == n);
BOOST_CHECK(s.capacity() == N);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
if ( 1 < n )
{
BOOST_CHECK(v == s[0]);
@@ -154,17 +145,23 @@
varray<T, N> s;
BOOST_CHECK(s.size() == 0);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
for ( size_t i = 0 ; i < N ; ++i )
{
- s.push_back(T(i));
+ T t(i);
+ s.push_back(t);
BOOST_CHECK(s.size() == i + 1);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(i + 1), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
BOOST_CHECK(T(i) == s.at(i));
BOOST_CHECK(T(i) == s[i]);
BOOST_CHECK(T(i) == s.back());
BOOST_CHECK(T(0) == s.front());
+ BOOST_CHECK(T(i) == *(s.data() + i));
}
}
@@ -174,13 +171,18 @@
varray<T, N> s;
for ( size_t i = 0 ; i < N ; ++i )
- s.push_back(T(i));
+ {
+ T t(i);
+ s.push_back(t);
+ }
for ( size_t i = N ; i > 1 ; --i )
{
s.pop_back();
BOOST_CHECK(s.size() == i - 1);
+#ifndef BOOST_NO_EXCEPTIONS
BOOST_CHECK_THROW( s.at(i - 1), std::out_of_range );
+#endif // BOOST_NO_EXCEPTIONS
BOOST_CHECK(T(i - 2) == s.at(i - 2));
BOOST_CHECK(T(i - 2) == s[i - 2]);
BOOST_CHECK(T(i - 2) == s.back());
@@ -196,6 +198,23 @@
BOOST_CHECK(*first1 == *first2);
}
+template <typename T, size_t N, typename C>
+void test_copy_and_assign(C const& c)
+{
+ {
+ varray<T, N> s(c.begin(), c.end());
+ BOOST_CHECK(s.size() == c.size());
+ test_compare_ranges(s.begin(), s.end(), c.begin(), c.end());
+ }
+ {
+ varray<T, N> s;
+ BOOST_CHECK(0 == s.size());
+ s.assign(c.begin(), c.end());
+ BOOST_CHECK(s.size() == c.size());
+ test_compare_ranges(s.begin(), s.end(), c.begin(), c.end());
+ }
+}
+
template <typename T, size_t N>
void test_copy_and_assign_nd(T const& val)
{
@@ -205,9 +224,10 @@
for ( size_t i = 0 ; i < N ; ++i )
{
- s.push_back(T(i));
- v.push_back(T(i));
- l.push_back(T(i));
+ T t(i);
+ s.push_back(t);
+ v.push_back(t);
+ l.push_back(t);
}
// copy ctor
{
@@ -223,44 +243,12 @@
BOOST_CHECK(s.size() == s1.size());
test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
}
- // ctor(Iter, Iter)
- {
- varray<T, N> s1(s.begin(), s.end());
- BOOST_CHECK(s.size() == s1.size());
- test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
- }
- {
- varray<T, N> s1(v.begin(), v.end());
- BOOST_CHECK(v.size() == s1.size());
- test_compare_ranges(v.begin(), v.end(), s1.begin(), s1.end());
- }
- {
- varray<T, N> s1(l.begin(), l.end());
- BOOST_CHECK(l.size() == s1.size());
- test_compare_ranges(l.begin(), l.end(), s1.begin(), s1.end());
- }
- // assign(Iter, Iter)
- {
- varray<T, N> s1;
- BOOST_CHECK(0 == s1.size());
- s1.assign(s.begin(), s.end());
- BOOST_CHECK(s.size() == s1.size());
- test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
- }
- {
- varray<T, N> s1;
- BOOST_CHECK(0 == s1.size());
- s1.assign(v.begin(), v.end());
- BOOST_CHECK(v.size() == s1.size());
- test_compare_ranges(v.begin(), v.end(), s1.begin(), s1.end());
- }
- {
- varray<T, N> s1;
- BOOST_CHECK(0 == s1.size());
- s1.assign(l.begin(), l.end());
- BOOST_CHECK(l.size() == s1.size());
- test_compare_ranges(l.begin(), l.end(), s1.begin(), s1.end());
- }
+
+ // ctor(Iter, Iter) and assign(Iter, Iter)
+ test_copy_and_assign<T, N>(s);
+ test_copy_and_assign<T, N>(v);
+ test_copy_and_assign<T, N>(l);
+
// assign(N, V)
{
varray<T, N> s1(s);
@@ -269,6 +257,13 @@
s1.assign(N, val);
test_compare_ranges(a.begin(), a.end(), s1.begin(), s1.end());
}
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+ stable_vector<T> bsv(s.begin(), s.end());
+ vector<T> bv(s.begin(), s.end());
+ test_copy_and_assign<T, N>(bsv);
+ test_copy_and_assign<T, N>(bv);
+#endif
}
template <typename T, size_t N>
@@ -296,7 +291,8 @@
void test_erase_nd()
{
varray<T, N> s;
-
+ typedef typename varray<T, N>::iterator It;
+
for ( size_t i = 0 ; i < N ; ++i )
s.push_back(T(i));
@@ -305,13 +301,14 @@
for ( size_t i = 0 ; i < N ; ++i )
{
varray<T, N> s1(s);
- s1.erase(s1.begin() + i);
+ It it = s1.erase(s1.begin() + i);
+ BOOST_CHECK(s1.begin() + i == it);
BOOST_CHECK(s1.size() == N - 1);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_CHECK(s1[j] == T(j));
for ( size_t j = i+1 ; j < N ; ++j )
BOOST_CHECK(s1[j-1] == T(j));
- }
+ }
}
// erase(first, last)
{
@@ -320,13 +317,40 @@
{
varray<T, N> s1(s);
size_t removed = i + n < N ? n : N - i;
- s1.erase(s1.begin() + i, s1.begin() + i + removed);
+ It it = s1.erase(s1.begin() + i, s1.begin() + i + removed);
+ BOOST_CHECK(s1.begin() + i == it);
BOOST_CHECK(s1.size() == N - removed);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_CHECK(s1[j] == T(j));
for ( size_t j = i+n ; j < N ; ++j )
BOOST_CHECK(s1[j-n] == T(j));
- }
+ }
+ }
+}
+
+template <typename T, size_t N, typename SV, typename C>
+void test_insert(SV const& s, C const& c)
+{
+ size_t h = N/2;
+ size_t n = size_t(h/1.5f);
+
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ varray<T, N> s1(s);
+
+ typename C::const_iterator it = c.begin();
+ std::advance(it, n);
+ typename varray<T, N>::iterator
+ it1 = s1.insert(s1.begin() + i, c.begin(), it);
+
+ BOOST_CHECK(s1.begin() + i == it1);
+ BOOST_CHECK(s1.size() == h+n);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = 0 ; j < n ; ++j )
+ BOOST_CHECK(s1[j+i] == T(100 + j));
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+n] == T(j+i));
}
}
@@ -339,6 +363,8 @@
std::vector<T> v;
std::list<T> l;
+ typedef typename varray<T, N>::iterator It;
+
for ( size_t i = 0 ; i < h ; ++i )
{
s.push_back(T(i));
@@ -352,14 +378,15 @@
for ( size_t i = 0 ; i <= h ; ++i )
{
varray<T, N> s1(s);
- s1.insert(s1.begin() + i, val);
+ It it = s1.insert(s1.begin() + i, val);
+ BOOST_CHECK(s1.begin() + i == it);
BOOST_CHECK(s1.size() == h+1);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_CHECK(s1[j] == T(j));
BOOST_CHECK(s1[i] == val);
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_CHECK(s1[j+i+1] == T(j+i));
- }
+ }
}
// insert(pos, n, val)
{
@@ -367,7 +394,8 @@
for ( size_t i = 0 ; i <= h ; ++i )
{
varray<T, N> s1(s);
- s1.insert(s1.begin() + i, n, val);
+ It it = s1.insert(s1.begin() + i, n, val);
+ BOOST_CHECK(s1.begin() + i == it);
BOOST_CHECK(s1.size() == h+n);
for ( size_t j = 0 ; j < i ; ++j )
BOOST_CHECK(s1[j] == T(j));
@@ -375,58 +403,258 @@
BOOST_CHECK(s1[j+i] == val);
for ( size_t j = 0 ; j < h-i ; ++j )
BOOST_CHECK(s1[j+i+n] == T(j+i));
- }
+ }
}
// insert(pos, first, last)
- {
- size_t n = size_t(h/1.5f);
- for ( size_t i = 0 ; i <= h ; ++i )
+ test_insert<T, N>(s, ss);
+ test_insert<T, N>(s, v);
+ test_insert<T, N>(s, l);
+
+#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+ stable_vector<T> bsv(ss.begin(), ss.end());
+ vector<T> bv(ss.begin(), ss.end());
+ test_insert<T, N>(s, bv);
+ test_insert<T, N>(s, bsv);
+#endif
+}
+
+template <typename T>
+void test_capacity_0_nd()
+{
+ varray<T, 10> v(5u, T(0));
+
+ //varray<T, 0, bad_alloc_strategy<T> > s;
+ varray<T, 0> s;
+ BOOST_CHECK(s.size() == 0);
+ BOOST_CHECK(s.capacity() == 0);
+#ifndef BOOST_NO_EXCEPTIONS
+ BOOST_CHECK_THROW(s.at(0), std::out_of_range);
+ //BOOST_CHECK_THROW(s.resize(5u, T(0)), std::bad_alloc);
+ //BOOST_CHECK_THROW(s.push_back(T(0)), std::bad_alloc);
+ //BOOST_CHECK_THROW(s.insert(s.end(), T(0)), std::bad_alloc);
+ //BOOST_CHECK_THROW(s.insert(s.end(), 5u, T(0)), std::bad_alloc);
+ //BOOST_CHECK_THROW(s.insert(s.end(), v.begin(), v.end()), std::bad_alloc);
+ //BOOST_CHECK_THROW(s.assign(v.begin(), v.end()), std::bad_alloc);
+ //BOOST_CHECK_THROW(s.assign(5u, T(0)), std::bad_alloc);
+ //try{
+ // varray<T, 0, bad_alloc_strategy<T> > s2(v.begin(), v.end());
+ // BOOST_CHECK(false);
+ //}catch(std::bad_alloc &){}
+ //try{
+ // varray<T, 0, bad_alloc_strategy<T> > s1(5u, T(0));
+ // BOOST_CHECK(false);
+ //}catch(std::bad_alloc &){}
+#endif // BOOST_NO_EXCEPTIONS
+}
+
+template <typename T, size_t N>
+void test_exceptions_nd()
+{
+ varray<T, N> v(N, T(0));
+ //varray<T, N/2, bad_alloc_strategy<T> > s(N/2, T(0));
+ varray<T, N/2> s(N/2, T(0));
+
+#ifndef BOOST_NO_EXCEPTIONS
+ /*BOOST_CHECK_THROW(s.resize(N, T(0)), std::bad_alloc);
+ BOOST_CHECK_THROW(s.push_back(T(0)), std::bad_alloc);
+ BOOST_CHECK_THROW(s.insert(s.end(), T(0)), std::bad_alloc);
+ BOOST_CHECK_THROW(s.insert(s.end(), N, T(0)), std::bad_alloc);
+ BOOST_CHECK_THROW(s.insert(s.end(), v.begin(), v.end()), std::bad_alloc);
+ BOOST_CHECK_THROW(s.assign(v.begin(), v.end()), std::bad_alloc);
+ BOOST_CHECK_THROW(s.assign(N, T(0)), std::bad_alloc);
+ try{
+ container_detail::varray<T, N/2, bad_alloc_strategy<T> > s2(v.begin(), v.end());
+ BOOST_CHECK(false);
+ }catch(std::bad_alloc &){}
+ try{
+ container_detail::varray<T, N/2, bad_alloc_strategy<T> > s1(N, T(0));
+ BOOST_CHECK(false);
+ }catch(std::bad_alloc &){}*/
+#endif // BOOST_NO_EXCEPTIONS
+}
+
+template <typename T, size_t N>
+void test_swap_and_move_nd()
+{
+ {
+ varray<T, N> v1, v2, v3, v4;
+ varray<T, N> s1, s2;
+ //varray<T, N, bad_alloc_strategy<T> > s4;
+ varray<T, N> s4;
+
+ for (size_t i = 0 ; i < N ; ++i )
{
- varray<T, N> s1(s);
- s1.insert(s1.begin() + i, ss.begin(), ss.begin() + n);
- BOOST_CHECK(s1.size() == h+n);
- for ( size_t j = 0 ; j < i ; ++j )
- BOOST_CHECK(s1[j] == T(j));
- for ( size_t j = 0 ; j < n ; ++j )
- BOOST_CHECK(s1[j+i] == T(100 + j));
- for ( size_t j = 0 ; j < h-i ; ++j )
- BOOST_CHECK(s1[j+i+n] == T(j+i));
- }
+ v1.push_back(T(i));
+ v2.push_back(T(i));
+ v3.push_back(T(i));
+ v4.push_back(T(i));
+ }
+ for (size_t i = 0 ; i < N/2 ; ++i )
+ {
+ s1.push_back(T(100 + i));
+ s2.push_back(T(100 + i));
+ s4.push_back(T(100 + i));
+ }
+
+ s1.swap(v1);
+ s2 = boost::move(v2);
+ varray<T, N> s3(boost::move(v3));
+ s4.swap(v4);
+
+ BOOST_CHECK(v1.size() == N/2);
+ BOOST_CHECK(s1.size() == N);
+ BOOST_CHECK(v2.size() == N); // objects aren't destroyed
+ BOOST_CHECK(s2.size() == N);
+ BOOST_CHECK(v3.size() == N); // objects aren't destroyed
+ BOOST_CHECK(s3.size() == N);
+ BOOST_CHECK(v4.size() == N/2);
+ BOOST_CHECK(s4.size() == N);
+ for (size_t i = 0 ; i < N/2 ; ++i )
+ {
+ BOOST_CHECK(v1[i] == T(100 + i));
+ BOOST_CHECK(v4[i] == T(100 + i));
+ }
+ for (size_t i = 0 ; i < N ; ++i )
+ {
+ BOOST_CHECK(s1[i] == T(i));
+ BOOST_CHECK(s2[i] == T(i));
+ BOOST_CHECK(s3[i] == T(i));
+ BOOST_CHECK(s4[i] == T(i));
+ }
}
{
- size_t n = size_t(h/1.5f);
- for ( size_t i = 0 ; i <= h ; ++i )
+ varray<T, N> v1, v2, v3;
+ varray<T, N/2> s1, s2;
+
+ for (size_t i = 0 ; i < N/2 ; ++i )
{
- varray<T, N> s1(s);
- s1.insert(s1.begin() + i, v.begin(), v.begin() + n);
- BOOST_CHECK(s1.size() == h+n);
- for ( size_t j = 0 ; j < i ; ++j )
- BOOST_CHECK(s1[j] == T(j));
- for ( size_t j = 0 ; j < n ; ++j )
- BOOST_CHECK(s1[j+i] == T(100 + j));
- for ( size_t j = 0 ; j < h-i ; ++j )
- BOOST_CHECK(s1[j+i+n] == T(j+i));
- }
+ v1.push_back(T(i));
+ v2.push_back(T(i));
+ v3.push_back(T(i));
+ }
+ for (size_t i = 0 ; i < N/3 ; ++i )
+ {
+ s1.push_back(T(100 + i));
+ s2.push_back(T(100 + i));
+ }
+
+ s1.swap(v1);
+ s2 = boost::move(v2);
+ varray<T, N/2> s3(boost::move(v3));
+
+ BOOST_CHECK(v1.size() == N/3);
+ BOOST_CHECK(s1.size() == N/2);
+ BOOST_CHECK(v2.size() == N/2); // objects aren't destroyed
+ BOOST_CHECK(s2.size() == N/2);
+ BOOST_CHECK(v3.size() == N/2); // objects aren't destroyed
+ BOOST_CHECK(s3.size() == N/2);
+ for (size_t i = 0 ; i < N/3 ; ++i )
+ BOOST_CHECK(v1[i] == T(100 + i));
+ for (size_t i = 0 ; i < N/2 ; ++i )
+ {
+ BOOST_CHECK(s1[i] == T(i));
+ BOOST_CHECK(s2[i] == T(i));
+ BOOST_CHECK(s3[i] == T(i));
+ }
}
{
- size_t n = size_t(h/1.5f);
- for ( size_t i = 0 ; i <= h ; ++i )
+ varray<T, N> v(N, T(0));
+ //varray<T, N/2, bad_alloc_strategy<T> > s(N/2, T(1));
+ varray<T, N/2> s(N/2, T(1));
+#ifndef BOOST_NO_EXCEPTIONS
+ //BOOST_CHECK_THROW(s.swap(v), std::bad_alloc);
+ //v.resize(N, T(0));
+ //BOOST_CHECK_THROW(s = boost::move(v), std::bad_alloc);
+ //v.resize(N, T(0));
+ //try {
+ // varray<T, N/2, bad_alloc_strategy<T> > s2(boost::move(v));
+ // BOOST_CHECK(false);
+ //} catch (std::bad_alloc &) {}
+#endif // BOOST_NO_EXCEPTIONS
+ }
+}
+
+template <typename T, size_t N>
+void test_emplace_0p()
+{
+ //emplace_back()
+ {
+ //varray<T, N, bad_alloc_strategy<T> > v;
+ varray<T, N> v;
+
+ for (int i = 0 ; i < int(N) ; ++i )
+ v.emplace_back();
+ BOOST_CHECK(v.size() == N);
+#ifndef BOOST_NO_EXCEPTIONS
+ //BOOST_CHECK_THROW(v.emplace_back(), std::bad_alloc);
+#endif
+ }
+}
+
+template <typename T, size_t N>
+void test_emplace_2p()
+{
+ //emplace_back(pos, int, int)
+ {
+ //varray<T, N, bad_alloc_strategy<T> > v;
+ varray<T, N> v;
+
+ for (int i = 0 ; i < int(N) ; ++i )
+ v.emplace_back(i, 100 + i);
+ BOOST_CHECK(v.size() == N);
+#ifndef BOOST_NO_EXCEPTIONS
+ //BOOST_CHECK_THROW(v.emplace_back(N, 100 + N), std::bad_alloc);
+#endif
+ BOOST_CHECK(v.size() == N);
+ for (int i = 0 ; i < int(N) ; ++i )
+ BOOST_CHECK(v[i] == T(i, 100 + i));
+ }
+
+ // emplace(pos, int, int)
+ {
+ //typedef typename varray<T, N, bad_alloc_strategy<T> >::iterator It;
+ typedef typename varray<T, N>::iterator It;
+
+ int h = N / 2;
+
+ //varray<T, N, bad_alloc_strategy<T> > v;
+ varray<T, N> v;
+ for ( int i = 0 ; i < h ; ++i )
+ v.emplace_back(i, 100 + i);
+
+ for ( int i = 0 ; i <= h ; ++i )
{
- varray<T, N> s1(s);
- typename std::list<T>::iterator it = l.begin();
- std::advance(it, n);
- s1.insert(s1.begin() + i, l.begin(), it);
- BOOST_CHECK(s1.size() == h+n);
- for ( size_t j = 0 ; j < i ; ++j )
- BOOST_CHECK(s1[j] == T(j));
- for ( size_t j = 0 ; j < n ; ++j )
- BOOST_CHECK(s1[j+i] == T(100 + j));
- for ( size_t j = 0 ; j < h-i ; ++j )
- BOOST_CHECK(s1[j+i+n] == T(j+i));
- }
+ //varray<T, N, bad_alloc_strategy<T> > vv(v);
+ varray<T, N> vv(v);
+ It it = vv.emplace(vv.begin() + i, i+100, i+200);
+ BOOST_CHECK(vv.begin() + i == it);
+ BOOST_CHECK(vv.size() == size_t(h+1));
+ for ( int j = 0 ; j < i ; ++j )
+ BOOST_CHECK(vv[j] == T(j, j+100));
+ BOOST_CHECK(vv[i] == T(i+100, i+200));
+ for ( int j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(vv[j+i+1] == T(j+i, j+i+100));
+ }
}
}
+template <typename T, size_t N>
+void test_sv_elem(T const& t)
+{
+ //typedef varray<T, N, bad_alloc_strategy<T> > V;
+ typedef varray<T, N> V;
+
+ //varray<V, N, bad_alloc_strategy<V> > v;
+ varray<V, N> v;
+
+ v.push_back(V(N/2, t));
+ V vvv(N/2, t);
+ v.push_back(boost::move(vvv));
+ v.insert(v.begin(), V(N/2, t));
+ v.insert(v.end(), V(N/2, t));
+ v.emplace_back(N/2, t);
+}
+
int test_main(int, char* [])
{
BOOST_CHECK(counting_value::count() == 0);
@@ -435,56 +663,112 @@
test_ctor_ndc<value_ndc, 10>();
test_ctor_ndc<counting_value, 10>();
BOOST_CHECK(counting_value::count() == 0);
+ test_ctor_ndc<shptr_value, 10>();
+ test_ctor_ndc<copy_movable, 10>();
test_ctor_nc<int, 10>(5);
test_ctor_nc<value_nc, 10>(5);
test_ctor_nc<counting_value, 10>(5);
BOOST_CHECK(counting_value::count() == 0);
+ test_ctor_nc<shptr_value, 10>(5);
+ test_ctor_nc<copy_movable, 10>(5);
test_ctor_nd<int, 10>(5, 1);
test_ctor_nd<value_nd, 10>(5, value_nd(1));
test_ctor_nd<counting_value, 10>(5, counting_value(1));
BOOST_CHECK(counting_value::count() == 0);
+ test_ctor_nd<shptr_value, 10>(5, shptr_value(1));
+ test_ctor_nd<copy_movable, 10>(5, produce());
test_resize_nc<int, 10>(5);
test_resize_nc<value_nc, 10>(5);
test_resize_nc<counting_value, 10>(5);
BOOST_CHECK(counting_value::count() == 0);
+ test_resize_nc<shptr_value, 10>(5);
+ test_resize_nc<copy_movable, 10>(5);
test_resize_nd<int, 10>(5, 1);
test_resize_nd<value_nd, 10>(5, value_nd(1));
test_resize_nd<counting_value, 10>(5, counting_value(1));
BOOST_CHECK(counting_value::count() == 0);
+ test_resize_nd<shptr_value, 10>(5, shptr_value(1));
+ test_resize_nd<copy_movable, 10>(5, produce());
test_push_back_nd<int, 10>();
test_push_back_nd<value_nd, 10>();
test_push_back_nd<counting_value, 10>();
BOOST_CHECK(counting_value::count() == 0);
+ test_push_back_nd<shptr_value, 10>();
+ test_push_back_nd<copy_movable, 10>();
test_pop_back_nd<int, 10>();
test_pop_back_nd<value_nd, 10>();
test_pop_back_nd<counting_value, 10>();
BOOST_CHECK(counting_value::count() == 0);
+ test_pop_back_nd<shptr_value, 10>();
+ test_pop_back_nd<copy_movable, 10>();
test_copy_and_assign_nd<int, 10>(1);
test_copy_and_assign_nd<value_nd, 10>(value_nd(1));
test_copy_and_assign_nd<counting_value, 10>(counting_value(1));
BOOST_CHECK(counting_value::count() == 0);
+ test_copy_and_assign_nd<shptr_value, 10>(shptr_value(1));
+ test_copy_and_assign_nd<copy_movable, 10>(produce());
test_iterators_nd<int, 10>();
test_iterators_nd<value_nd, 10>();
test_iterators_nd<counting_value, 10>();
BOOST_CHECK(counting_value::count() == 0);
+ test_iterators_nd<shptr_value, 10>();
+ test_iterators_nd<copy_movable, 10>();
test_erase_nd<int, 10>();
test_erase_nd<value_nd, 10>();
test_erase_nd<counting_value, 10>();
BOOST_CHECK(counting_value::count() == 0);
+ test_erase_nd<shptr_value, 10>();
+ test_erase_nd<copy_movable, 10>();
test_insert_nd<int, 10>(50);
test_insert_nd<value_nd, 10>(value_nd(50));
test_insert_nd<counting_value, 10>(counting_value(50));
BOOST_CHECK(counting_value::count() == 0);
+ test_insert_nd<shptr_value, 10>(shptr_value(50));
+ test_insert_nd<copy_movable, 10>(produce());
+
+ test_capacity_0_nd<int>();
+ test_capacity_0_nd<value_nd>();
+ test_capacity_0_nd<counting_value>();
+ BOOST_CHECK(counting_value::count() == 0);
+ test_capacity_0_nd<shptr_value>();
+ test_capacity_0_nd<copy_movable>();
+
+ test_exceptions_nd<int, 10>();
+ test_exceptions_nd<value_nd, 10>();
+ test_exceptions_nd<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+ test_exceptions_nd<shptr_value, 10>();
+ test_exceptions_nd<copy_movable, 10>();
+
+ test_swap_and_move_nd<int, 10>();
+ test_swap_and_move_nd<value_nd, 10>();
+ test_swap_and_move_nd<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+ test_swap_and_move_nd<shptr_value, 10>();
+ test_swap_and_move_nd<copy_movable, 10>();
+
+ test_emplace_0p<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_emplace_2p<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_sv_elem<int, 10>(50);
+ test_sv_elem<value_nd, 10>(value_nd(50));
+ test_sv_elem<counting_value, 10>(counting_value(50));
+ BOOST_CHECK(counting_value::count() == 0);
+ test_sv_elem<shptr_value, 10>(shptr_value(50));
+ test_sv_elem<copy_movable, 10>(copy_movable(50));
return 0;
}
Added: trunk/libs/geometry/index/test/varray_old.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/geometry/index/test/varray_old.cpp 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013) (r84676)
@@ -0,0 +1,490 @@
+// Boost.Geometry Index
+// Unit Test
+
+// Copyright (c) 2011-2013 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 <boost/test/included/test_exec_monitor.hpp>
+#include <boost/test/impl/execution_monitor.ipp>
+
+#include <boost/geometry/index/detail/varray.hpp>
+
+using namespace boost::geometry::index::detail;
+
+class value_ndc
+{
+public:
+ explicit value_ndc(int a) : aa(a) {}
+ ~value_ndc() {}
+ bool operator==(value_ndc const& v) const { return aa == v.aa; }
+private:
+ value_ndc(value_ndc const&) {}
+ value_ndc & operator=(value_ndc const&) { return *this; }
+ int aa;
+};
+
+class value_nd
+{
+public:
+ explicit value_nd(int a) : aa(a) {}
+ ~value_nd() {}
+ bool operator==(value_nd const& v) const { return aa == v.aa; }
+private:
+ int aa;
+};
+
+class value_nc
+{
+public:
+ explicit value_nc(int a = 0) : aa(a) {}
+ ~value_nc() {}
+ bool operator==(value_nc const& v) const { return aa == v.aa; }
+private:
+ value_nc(value_nc const&) {}
+ value_nc & operator=(value_ndc const&) { return *this; }
+ int aa;
+};
+
+class counting_value
+{
+public:
+ explicit counting_value(int a = 0) : aa(a) { ++c(); }
+ counting_value(counting_value const& v) : aa(v.aa) { ++c(); }
+ counting_value & operator=(counting_value const& v) { aa = v.aa; return *this; }
+ ~counting_value() { --c(); }
+ bool operator==(counting_value const& v) const { return aa == v.aa; }
+ static size_t count() { return c(); }
+private:
+ static size_t & c() { static size_t co = 0; return co; }
+ int aa;
+};
+
+template <typename T, size_t N>
+void test_ctor_ndc()
+{
+ varray<T, N> s;
+ BOOST_CHECK(s.size() == 0);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+}
+
+template <typename T, size_t N>
+void test_ctor_nc(size_t n)
+{
+ varray<T, N> s(n);
+ BOOST_CHECK(s.size() == n);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+ if ( !boost::has_trivial_constructor<T>::value )
+ {
+ for ( size_t i = 0 ; i < n ; ++i )
+ BOOST_CHECK(T() == s[i]);
+ }
+}
+
+template <typename T, size_t N>
+void test_ctor_nd(size_t n, T const& v)
+{
+ varray<T, N> s(n, v);
+ BOOST_CHECK(s.size() == n);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+ if ( 1 < n )
+ {
+ BOOST_CHECK(v == s[0]);
+ BOOST_CHECK(v == s.at(0));
+ BOOST_CHECK(v == s[1]);
+ BOOST_CHECK(v == s.at(1));
+ s[0] = T(10);
+ BOOST_CHECK(T(10) == s[0]);
+ BOOST_CHECK(T(10) == s.at(0));
+ s.at(1) = T(20);
+ BOOST_CHECK(T(20) == s[1]);
+ BOOST_CHECK(T(20) == s.at(1));
+ }
+}
+
+template <typename T, size_t N>
+void test_resize_nc(size_t n)
+{
+ varray<T, N> s;
+
+ s.resize(n);
+ BOOST_CHECK(s.size() == n);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+
+ if ( !boost::has_trivial_constructor<T>::value )
+ {
+ for ( size_t i = 0 ; i < n ; ++i )
+ BOOST_CHECK(T() == s[i]);
+ }
+}
+
+template <typename T, size_t N>
+void test_resize_nd(size_t n, T const& v)
+{
+ varray<T, N> s;
+
+ s.resize(n, v);
+ BOOST_CHECK(s.size() == n);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+ if ( 1 < n )
+ {
+ BOOST_CHECK(v == s[0]);
+ BOOST_CHECK(v == s.at(0));
+ BOOST_CHECK(v == s[1]);
+ BOOST_CHECK(v == s.at(1));
+ s[0] = T(10);
+ BOOST_CHECK(T(10) == s[0]);
+ BOOST_CHECK(T(10) == s.at(0));
+ s.at(1) = T(20);
+ BOOST_CHECK(T(20) == s[1]);
+ BOOST_CHECK(T(20) == s.at(1));
+ }
+}
+
+template <typename T, size_t N>
+void test_push_back_nd()
+{
+ varray<T, N> s;
+
+ BOOST_CHECK(s.size() == 0);
+ BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ {
+ s.push_back(T(i));
+ BOOST_CHECK(s.size() == i + 1);
+ BOOST_CHECK_THROW( s.at(i + 1), std::out_of_range );
+ BOOST_CHECK(T(i) == s.at(i));
+ BOOST_CHECK(T(i) == s[i]);
+ BOOST_CHECK(T(i) == s.back());
+ BOOST_CHECK(T(0) == s.front());
+ }
+}
+
+template <typename T, size_t N>
+void test_pop_back_nd()
+{
+ varray<T, N> s;
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ s.push_back(T(i));
+
+ for ( size_t i = N ; i > 1 ; --i )
+ {
+ s.pop_back();
+ BOOST_CHECK(s.size() == i - 1);
+ BOOST_CHECK_THROW( s.at(i - 1), std::out_of_range );
+ BOOST_CHECK(T(i - 2) == s.at(i - 2));
+ BOOST_CHECK(T(i - 2) == s[i - 2]);
+ BOOST_CHECK(T(i - 2) == s.back());
+ BOOST_CHECK(T(0) == s.front());
+ }
+}
+
+template <typename It1, typename It2>
+void test_compare_ranges(It1 first1, It1 last1, It2 first2, It2 last2)
+{
+ BOOST_CHECK(std::distance(first1, last1) == std::distance(first2, last2));
+ for ( ; first1 != last1 && first2 != last2 ; ++first1, ++first2 )
+ BOOST_CHECK(*first1 == *first2);
+}
+
+template <typename T, size_t N>
+void test_copy_and_assign_nd(T const& val)
+{
+ varray<T, N> s;
+ std::vector<T> v;
+ std::list<T> l;
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ {
+ s.push_back(T(i));
+ v.push_back(T(i));
+ l.push_back(T(i));
+ }
+ // copy ctor
+ {
+ varray<T, N> s1(s);
+ BOOST_CHECK(s.size() == s1.size());
+ test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
+ }
+ // copy assignment
+ {
+ varray<T, N> s1;
+ BOOST_CHECK(0 == s1.size());
+ s1 = s;
+ BOOST_CHECK(s.size() == s1.size());
+ test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
+ }
+ // ctor(Iter, Iter)
+ {
+ varray<T, N> s1(s.begin(), s.end());
+ BOOST_CHECK(s.size() == s1.size());
+ test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
+ }
+ {
+ varray<T, N> s1(v.begin(), v.end());
+ BOOST_CHECK(v.size() == s1.size());
+ test_compare_ranges(v.begin(), v.end(), s1.begin(), s1.end());
+ }
+ {
+ varray<T, N> s1(l.begin(), l.end());
+ BOOST_CHECK(l.size() == s1.size());
+ test_compare_ranges(l.begin(), l.end(), s1.begin(), s1.end());
+ }
+ // assign(Iter, Iter)
+ {
+ varray<T, N> s1;
+ BOOST_CHECK(0 == s1.size());
+ s1.assign(s.begin(), s.end());
+ BOOST_CHECK(s.size() == s1.size());
+ test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
+ }
+ {
+ varray<T, N> s1;
+ BOOST_CHECK(0 == s1.size());
+ s1.assign(v.begin(), v.end());
+ BOOST_CHECK(v.size() == s1.size());
+ test_compare_ranges(v.begin(), v.end(), s1.begin(), s1.end());
+ }
+ {
+ varray<T, N> s1;
+ BOOST_CHECK(0 == s1.size());
+ s1.assign(l.begin(), l.end());
+ BOOST_CHECK(l.size() == s1.size());
+ test_compare_ranges(l.begin(), l.end(), s1.begin(), s1.end());
+ }
+ // assign(N, V)
+ {
+ varray<T, N> s1(s);
+ test_compare_ranges(s.begin(), s.end(), s1.begin(), s1.end());
+ std::vector<T> a(N, val);
+ s1.assign(N, val);
+ test_compare_ranges(a.begin(), a.end(), s1.begin(), s1.end());
+ }
+}
+
+template <typename T, size_t N>
+void test_iterators_nd()
+{
+ varray<T, N> s;
+ std::vector<T> v;
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ {
+ s.push_back(T(i));
+ v.push_back(T(i));
+ }
+
+ test_compare_ranges(s.begin(), s.end(), v.begin(), v.end());
+ test_compare_ranges(s.rbegin(), s.rend(), v.rbegin(), v.rend());
+
+ s.assign(v.rbegin(), v.rend());
+
+ test_compare_ranges(s.begin(), s.end(), v.rbegin(), v.rend());
+ test_compare_ranges(s.rbegin(), s.rend(), v.begin(), v.end());
+}
+
+template <typename T, size_t N>
+void test_erase_nd()
+{
+ varray<T, N> s;
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ s.push_back(T(i));
+
+ // erase(pos)
+ {
+ for ( size_t i = 0 ; i < N ; ++i )
+ {
+ varray<T, N> s1(s);
+ s1.erase(s1.begin() + i);
+ BOOST_CHECK(s1.size() == N - 1);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = i+1 ; j < N ; ++j )
+ BOOST_CHECK(s1[j-1] == T(j));
+ }
+ }
+ // erase(first, last)
+ {
+ size_t n = N/3;
+ for ( size_t i = 0 ; i <= N ; ++i )
+ {
+ varray<T, N> s1(s);
+ size_t removed = i + n < N ? n : N - i;
+ s1.erase(s1.begin() + i, s1.begin() + i + removed);
+ BOOST_CHECK(s1.size() == N - removed);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = i+n ; j < N ; ++j )
+ BOOST_CHECK(s1[j-n] == T(j));
+ }
+ }
+}
+
+template <typename T, size_t N>
+void test_insert_nd(T const& val)
+{
+ size_t h = N/2;
+
+ varray<T, N> s, ss;
+ std::vector<T> v;
+ std::list<T> l;
+
+ for ( size_t i = 0 ; i < h ; ++i )
+ {
+ s.push_back(T(i));
+ ss.push_back(T(100 + i));
+ v.push_back(T(100 + i));
+ l.push_back(T(100 + i));
+ }
+
+ // insert(pos, val)
+ {
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ varray<T, N> s1(s);
+ s1.insert(s1.begin() + i, val);
+ BOOST_CHECK(s1.size() == h+1);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ BOOST_CHECK(s1[i] == val);
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+1] == T(j+i));
+ }
+ }
+ // insert(pos, n, val)
+ {
+ size_t n = size_t(h/1.5f);
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ varray<T, N> s1(s);
+ s1.insert(s1.begin() + i, n, val);
+ BOOST_CHECK(s1.size() == h+n);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = 0 ; j < n ; ++j )
+ BOOST_CHECK(s1[j+i] == val);
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+n] == T(j+i));
+ }
+ }
+ // insert(pos, first, last)
+ {
+ size_t n = size_t(h/1.5f);
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ varray<T, N> s1(s);
+ s1.insert(s1.begin() + i, ss.begin(), ss.begin() + n);
+ BOOST_CHECK(s1.size() == h+n);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = 0 ; j < n ; ++j )
+ BOOST_CHECK(s1[j+i] == T(100 + j));
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+n] == T(j+i));
+ }
+ }
+ {
+ size_t n = size_t(h/1.5f);
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ varray<T, N> s1(s);
+ s1.insert(s1.begin() + i, v.begin(), v.begin() + n);
+ BOOST_CHECK(s1.size() == h+n);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = 0 ; j < n ; ++j )
+ BOOST_CHECK(s1[j+i] == T(100 + j));
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+n] == T(j+i));
+ }
+ }
+ {
+ size_t n = size_t(h/1.5f);
+ for ( size_t i = 0 ; i <= h ; ++i )
+ {
+ varray<T, N> s1(s);
+ typename std::list<T>::iterator it = l.begin();
+ std::advance(it, n);
+ s1.insert(s1.begin() + i, l.begin(), it);
+ BOOST_CHECK(s1.size() == h+n);
+ for ( size_t j = 0 ; j < i ; ++j )
+ BOOST_CHECK(s1[j] == T(j));
+ for ( size_t j = 0 ; j < n ; ++j )
+ BOOST_CHECK(s1[j+i] == T(100 + j));
+ for ( size_t j = 0 ; j < h-i ; ++j )
+ BOOST_CHECK(s1[j+i+n] == T(j+i));
+ }
+ }
+}
+
+int test_main(int, char* [])
+{
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_ctor_ndc<int, 10>();
+ test_ctor_ndc<value_ndc, 10>();
+ test_ctor_ndc<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_ctor_nc<int, 10>(5);
+ test_ctor_nc<value_nc, 10>(5);
+ test_ctor_nc<counting_value, 10>(5);
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_ctor_nd<int, 10>(5, 1);
+ test_ctor_nd<value_nd, 10>(5, value_nd(1));
+ test_ctor_nd<counting_value, 10>(5, counting_value(1));
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_resize_nc<int, 10>(5);
+ test_resize_nc<value_nc, 10>(5);
+ test_resize_nc<counting_value, 10>(5);
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_resize_nd<int, 10>(5, 1);
+ test_resize_nd<value_nd, 10>(5, value_nd(1));
+ test_resize_nd<counting_value, 10>(5, counting_value(1));
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_push_back_nd<int, 10>();
+ test_push_back_nd<value_nd, 10>();
+ test_push_back_nd<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_pop_back_nd<int, 10>();
+ test_pop_back_nd<value_nd, 10>();
+ test_pop_back_nd<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_copy_and_assign_nd<int, 10>(1);
+ test_copy_and_assign_nd<value_nd, 10>(value_nd(1));
+ test_copy_and_assign_nd<counting_value, 10>(counting_value(1));
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_iterators_nd<int, 10>();
+ test_iterators_nd<value_nd, 10>();
+ test_iterators_nd<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_erase_nd<int, 10>();
+ test_erase_nd<value_nd, 10>();
+ test_erase_nd<counting_value, 10>();
+ BOOST_CHECK(counting_value::count() == 0);
+
+ test_insert_nd<int, 10>(50);
+ test_insert_nd<value_nd, 10>(value_nd(50));
+ test_insert_nd<counting_value, 10>(counting_value(50));
+ BOOST_CHECK(counting_value::count() == 0);
+
+ return 0;
+}
Added: trunk/libs/geometry/index/test/varray_test.hpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/geometry/index/test/varray_test.hpp 2013-06-07 13:36:56 EDT (Fri, 07 Jun 2013) (r84676)
@@ -0,0 +1,97 @@
+// Boost.Geometry.Index varray
+// Unit Test
+
+// Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2012-2013 Andrew Hundt.
+
+// 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_GEOMETRY_INDEX_TEST_VARRAY_TEST_HPP
+#define BOOST_GEOMETRY_INDEX_TEST_VARRAY_TEST_HPP
+
+#include <boost/geometry/index/detail/varray.hpp>
+
+#include <boost/shared_ptr.hpp>
+#include "movable.hpp"
+
+class value_ndc
+{
+public:
+ explicit value_ndc(int a) : aa(a) {}
+ ~value_ndc() {}
+ bool operator==(value_ndc const& v) const { return aa == v.aa; }
+ bool operator<(value_ndc const& v) const { return aa < v.aa; }
+private:
+ value_ndc(value_ndc const&) {}
+ value_ndc & operator=(value_ndc const&) { return *this; }
+ int aa;
+};
+
+class value_nd
+{
+public:
+ explicit value_nd(int a) : aa(a) {}
+ ~value_nd() {}
+ bool operator==(value_nd const& v) const { return aa == v.aa; }
+ bool operator<(value_nd const& v) const { return aa < v.aa; }
+private:
+ int aa;
+};
+
+class value_nc
+{
+public:
+ explicit value_nc(int a = 0) : aa(a) {}
+ ~value_nc() {}
+ bool operator==(value_nc const& v) const { return aa == v.aa; }
+ bool operator<(value_nc const& v) const { return aa < v.aa; }
+private:
+ value_nc(value_nc const&) {}
+ value_nc & operator=(value_ndc const&) { return *this; }
+ int aa;
+};
+
+class counting_value
+{
+ BOOST_COPYABLE_AND_MOVABLE(counting_value)
+
+public:
+ explicit counting_value(int a = 0, int b = 0) : aa(a), bb(b) { ++c(); }
+ counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); }
+ counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); } // Move constructor
+ counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; } // Move assignment
+ counting_value& operator=(BOOST_COPY_ASSIGN_REF(counting_value) p) { aa = p.aa; bb = p.bb; return *this; } // Copy assignment
+ ~counting_value() { --c(); }
+ bool operator==(counting_value const& v) const { return aa == v.aa && bb == v.bb; }
+ bool operator<(counting_value const& v) const { return aa < v.aa || ( aa == v.aa && bb < v.bb ); }
+ static size_t count() { return c(); }
+
+private:
+ static size_t & c() { static size_t co = 0; return co; }
+ int aa, bb;
+};
+
+namespace boost {
+
+template <>
+struct has_nothrow_move<counting_value>
+{
+ static const bool value = true;
+};
+
+}
+
+class shptr_value
+{
+ typedef boost::shared_ptr<int> Ptr;
+public:
+ explicit shptr_value(int a = 0) : m_ptr(new int(a)) {}
+ bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); }
+ bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); }
+private:
+ boost::shared_ptr<int> m_ptr;
+};
+
+#endif // BOOST_GEOMETRY_INDEX_TEST_VARRAY_TEST_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