Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81960 - in sandbox-branches/geometry/index: boost/geometry/extensions/index test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-14 17:59:19


Author: awulkiew
Date: 2012-12-14 17:59:19 EST (Fri, 14 Dec 2012)
New Revision: 81960
URL: http://svn.boost.org/trac/boost/changeset/81960

Log:
static_vector error fixed, tests added.
Text files modified:
   sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp | 2
   sandbox-branches/geometry/index/test/static_vector.cpp | 151 +++++++++++++++++++++++++++++++++++++--
   2 files changed, 143 insertions(+), 10 deletions(-)

Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp 2012-12-14 17:59:19 EST (Fri, 14 Dec 2012)
@@ -80,7 +80,7 @@
     {
         //BOOST_ASSERT_MSG(other.m_size <= Capacity, "capacity too small");
 
- assign(other->ptr(0), other->ptr(other.m_size));
+ assign(other.ptr(0), other.ptr(other.m_size));
 
         return *this;
     }

Modified: sandbox-branches/geometry/index/test/static_vector.cpp
==============================================================================
--- sandbox-branches/geometry/index/test/static_vector.cpp (original)
+++ sandbox-branches/geometry/index/test/static_vector.cpp 2012-12-14 17:59:19 EST (Fri, 14 Dec 2012)
@@ -18,6 +18,7 @@
 {
 public:
     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&) {}
@@ -29,6 +30,7 @@
 {
 public:
     value_nd(int a) : aa(a) {}
+ ~value_nd() {}
     bool operator==(value_nd const& v) const { return aa == v.aa; }
 private:
     int aa;
@@ -38,6 +40,7 @@
 {
 public:
     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&) {}
@@ -46,7 +49,7 @@
 };
 
 template <typename T, size_t N>
-void test_ctor_d()
+void test_ctor_ndc()
 {
     static_vector<T, N> s;
     BOOST_CHECK(s.size() == 0);
@@ -55,7 +58,7 @@
 }
 
 template <typename T, size_t N>
-void test_ctor_r(size_t n)
+void test_ctor_nc(size_t n)
 {
     static_vector<T, N> s(n);
     BOOST_CHECK(s.size() == n);
@@ -73,7 +76,7 @@
 }
 
 template <typename T, size_t N>
-void test_ctor_rv(size_t n, T const& v)
+void test_ctor_nd(size_t n, T const& v)
 {
     static_vector<T, N> s(n, v);
     BOOST_CHECK(s.size() == n);
@@ -94,14 +97,144 @@
     }
 }
 
+template <typename T, size_t N>
+void test_resize_nc(size_t n)
+{
+ static_vector<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 ( 1 < n )
+ {
+ 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_nd(size_t n, T const& v)
+{
+ static_vector<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()
+{
+ static_vector<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()
+{
+ static_vector<T, N> s;
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ s.push_back(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 T, size_t N>
+void test_copy_and_assign_nd()
+{
+ static_vector<T, N> s;
+
+ for ( size_t i = 0 ; i < N ; ++i )
+ s.push_back(i);
+
+ {
+ static_vector<T, N> s1(s);
+ BOOST_CHECK(s.size() == s1.size());
+ for ( size_t i = 0 ; i < N ; ++i )
+ BOOST_CHECK(s[i] == s1[i]) ;
+ }
+ {
+ static_vector<T, N> s1;
+ BOOST_CHECK(0 == s1.size());
+ s1 = s;
+ BOOST_CHECK(s.size() == s1.size());
+ for ( size_t i = 0 ; i < N ; ++i )
+ BOOST_CHECK(s[i] == s1[i]) ;
+ }
+ {
+ static_vector<T, N> s1;
+ BOOST_CHECK(0 == s1.size());
+ s1.assign(s.begin(), s.end());
+ BOOST_CHECK(s.size() == s1.size());
+ for ( size_t i = 0 ; i < N ; ++i )
+ BOOST_CHECK(s[i] == s1[i]) ;
+ }
+}
+
 int test_main(int, char* [])
 {
- test_ctor_d<int, 10>();
- test_ctor_d<value_ndc, 10>();
- test_ctor_r<int, 10>(5);
- test_ctor_r<value_nc, 10>(5);
- test_ctor_rv<int, 10>(5, 0);
- test_ctor_rv<value_nd, 10>(5, 0);
+ test_ctor_ndc<int, 10>();
+ test_ctor_ndc<value_ndc, 10>();
+ test_ctor_nc<int, 10>(5);
+ test_ctor_nc<value_nc, 10>(5);
+ test_ctor_nd<int, 10>(5, 1);
+ test_ctor_nd<value_nd, 10>(5, 1);
+
+ test_resize_nc<int, 10>(5);
+ test_resize_nc<value_nc, 10>(5);
+ test_resize_nd<int, 10>(5, 1);
+ test_resize_nd<value_nd, 10>(5, 1);
+
+ test_push_back_nd<int, 10>();
+ test_push_back_nd<value_nd, 10>();
+
+ test_pop_back_nd<int, 10>();
+ test_pop_back_nd<value_nd, 10>();
+
+ test_copy_and_assign_nd<int, 10>();
+ test_copy_and_assign_nd<value_nd, 10>();
 
     return 0;
 }


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