Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62944 - in sandbox/SOC/2010/bit_masks: boost/integer/details lib/integer/test/bft_testing
From: bbartmanboost_at_[hidden]
Date: 2010-06-14 14:29:58


Author: bbartman
Date: 2010-06-14 14:29:57 EDT (Mon, 14 Jun 2010)
New Revision: 62944
URL: http://svn.boost.org/trac/boost/changeset/62944

Log:
added corner case testing for twos complement
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/details/arbitrary_twos_complement.hpp | 1
   sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/twos_complement_testing.cpp | 42 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 43 insertions(+), 0 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/details/arbitrary_twos_complement.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/details/arbitrary_twos_complement.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/details/arbitrary_twos_complement.hpp 2010-06-14 14:29:57 EDT (Mon, 14 Jun 2010)
@@ -5,6 +5,7 @@
 
 #ifndef BOOST_ARBITRART_TWOS_COMPLEMENT_HPP
 #define BOOST_ARBITRART_TWOS_COMPLEMENT_HPP
+
 #include <boost/static_assert.hpp>
 #include <boost/integer/bits_mask.hpp>
 #include <boost/cstdint.hpp>

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/twos_complement_testing.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/twos_complement_testing.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bft_testing/twos_complement_testing.cpp 2010-06-14 14:29:57 EDT (Mon, 14 Jun 2010)
@@ -12,6 +12,7 @@
 
 using namespace boost;
 int main() {
+ // basic cast storing a negative number.
     {
         std::size_t storage = 0;
         char temp = -2;
@@ -21,6 +22,47 @@
         temp = twos_complement_decoding< unsigned int, 4, char >( storage );
         BOOST_ASSERT((temp == -2));
     }
+ // storing a non negative number with a signed type.
+ {
+ std::size_t storage = 0;
+ char temp = 2;
+ storage = twos_complement_encoding< char, 4, unsigned int >( temp );
+ BOOST_ASSERT((storage == bits_mask<std::size_t, 1>::value ));
+
+ temp = twos_complement_decoding< unsigned int, 4, char >( storage );
+ BOOST_ASSERT((temp == 2));
+ }
+ // storing an unsigned number
+ {
+ std::size_t storage = 0;
+ unsigned char temp = 2;
+ storage = twos_complement_encoding< unsigned char, 4, unsigned int >( temp );
+ BOOST_ASSERT((storage == bits_mask<std::size_t, 1>::value ));
+
+ temp = twos_complement_decoding< unsigned int, 4, unsigned char >( storage );
+ BOOST_ASSERT((temp == 2));
+ }
+ // corner case stroing a boolean
+ {
+ std::size_t storage = 0;
+ bool temp = true;
+ storage = twos_complement_encoding< bool, 4, unsigned int >( temp );
+ BOOST_ASSERT((storage == bits_mask<std::size_t, 0>::value ));
+
+ temp = twos_complement_decoding< unsigned int, 4, bool >( storage );
+ BOOST_ASSERT((temp == true));
+ }
+
+ // corner case storing a type with width one.
+ {
+ std::size_t storage = 0;
+ char temp = 1;
+ storage = twos_complement_encoding< char, 1, unsigned int >( temp );
+ BOOST_ASSERT((storage == bits_mask<std::size_t, 0>::value ));
+
+ temp = twos_complement_decoding< unsigned int, 1, char >( storage );
+ BOOST_ASSERT((temp == 1));
+ }
     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