Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67498 - in sandbox/SOC/2010/bit_masks: boost/integer lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-12-30 11:30:52


Author: bbartman
Date: 2010-12-30 11:30:46 EST (Thu, 30 Dec 2010)
New Revision: 67498
URL: http://svn.boost.org/trac/boost/changeset/67498

Log:
complete testing for fill assign and range assign
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 35 ++++++++++++++++------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp | 61 +++++++++++++++++++++++++++++++++++++--
   2 files changed, 82 insertions(+), 14 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp 2010-12-30 11:30:46 EST (Thu, 30 Dec 2010)
@@ -13,6 +13,7 @@
 #include <iterator>
 #include <limits>
 #include <stdexcept>
+#include <boost/assert.hpp>
 
 namespace boost {
 
@@ -758,15 +759,16 @@
     /** const at throwing indexing. */
     const_reference at(size_type n) const {
         if(n > size() ) {
- throw std::out_of_range();
+ throw std::out_of_range("Out of Range: invalid value for n.");
         }
         return (*this)[n];
     }
 
-
- template <class InputIterator>
- void assign(InputIterator first, InputIterator last);
- void assign(size_type n, value_type const& u);
+ /** Remove element from end of vector.*/
+ void pop_back() {
+ BOOST_ASSERT(( this->m_impl.m_bits_in_use != 0 ));
+ this->m_impl.m_bits_in_use -= Width;
+ }
 
     /** Add an element to the end of the vector. */
     void push_back(value_type const& x) {
@@ -775,7 +777,24 @@
         *iter = x;
         this->m_impl.m_bits_in_use += Width;
     }
- void pop_back();
+
+ template <class InputIterator>
+ void assign(InputIterator first, InputIterator last) {
+ clear();
+ // copy(first, last, std::back_inserter(*this) );
+ while(first != last) {
+ push_back(*first);
+ ++first;
+ }
+ }
+
+ void assign(size_type n, value_type const& u) {
+ clear();
+ for(size_type index=0; index<n;++index){
+ push_back(u);
+ }
+ }
+
     iterator insert(iterator position, value_type const& x);
     void insert(iterator position, size_type n, value_type const& x);
 
@@ -785,12 +804,8 @@
     iterator erase(iterator position);
     iterator erase(iterator first, iterator last);
 
-
 protected:
 
-
-
-
     /** allocates a chunck of memory of the correct size and then
      * correctly fills that memory with value for each of the
      * bitfields within it.

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp 2010-12-30 11:30:46 EST (Thu, 30 Dec 2010)
@@ -6,7 +6,7 @@
 
 #include <boost/integer/bitfield_vector.hpp>
 #include "test_utility.hpp"
-
+#include <vector>
 using namespace boost;
 
 /** This is done so that I can inherit from bitfield_vector and have access
@@ -377,11 +377,11 @@
         this->clear();
         for(std::size_t i=0; i < 3u; ++i) this->push_back(i);
         for(std::size_t i=0; i < 3u; ++i) {
- BOOST_TEST( const_cast<self const&>(*this)->at(i) == i);
+ BOOST_TEST( const_cast<self const&>(*this).at(i) == i);
         }
 
         try{
- const_cast<self const&>(*this)->at(100);
+ const_cast<self const&>(*this).at(100);
         }catch(std::out_of_range const&) {
             return;
         }catch(...) {
@@ -389,6 +389,45 @@
         }
         BOOST_TEST(!"Didn't catch Exception from at.");
     }
+
+ // pop back test.
+ void test_pop_back() {
+ this->clear();
+ this->push_back(1);
+ this->push_back(1);
+ BOOST_TEST(this->size() == 2);
+ this->pop_back();
+ BOOST_TEST(this->size() == 1);
+ this->pop_back();
+ BOOST_TEST(this->size() == 0);
+ }
+
+ // range assign
+ void test_range_assign() {
+ this->clear();
+ typedef std::vector<typename Bfv::value_type> temp_vector;
+ temp_vector temp;
+ for(std::size_t i=0; i<3;++i) {
+ temp.push_back(i);
+ }
+
+ this->assign(temp.begin(), temp.end());
+ for(std::size_t i=0; i<3;++i) {
+ BOOST_TEST((*this)[i] == i);
+ }
+ }
+
+ // fill assign
+ void test_fill_assign() {
+ this->clear();
+ this->assign(8,2);
+ BOOST_TEST(this->size() == 8);
+ for(std::size_t i=0; i < 8;++i) {
+ BOOST_TEST((*this)[i] == 2);
+ }
+ }
+
+
 };
 
 
@@ -542,8 +581,8 @@
     {
         Tester t1;
         t1.test_const_square_bracket_operator();
- }
 
+ }
     // at test
     {
         Tester t1;
@@ -552,6 +591,20 @@
 
     // const at test
     {
+ Tester t1;
+ t1.test_const_at();
+ }
+
+ // pop_back
+ {
+ Tester t1;
+ t1.test_pop_back();
+ }
+
+ // range assign
+ {
+ Tester t1;
+ t1.test_range_assign();
     }
 }
 


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