Update of /cvsroot/boost/boost/libs/dynamic_bitset
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv13948

Modified Files:
        bitset_test.hpp 
Log Message:
updated copyright notice (years); used <assert.h> instead of <cassert>; include 
"dynamic_bitset/dynamic_bitset.hpp"; added a comment related to a Borland 
numeric_limits<> issue; some cleanup; strengthened many tests

Index: bitset_test.hpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/dynamic_bitset/bitset_test.hpp,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- bitset_test.hpp     29 May 2006 16:40:15 -0000      1.18
+++ bitset_test.hpp     25 Jun 2006 19:16:48 -0000      1.19
@@ -1,6 +1,6 @@
 // --------------------------------------------------
 //        (C) Copyright Jeremy Siek   2001.
-//        (C) Copyright Gennaro Prota 2003 - 2004.
+//        (C) Copyright Gennaro Prota 2003 - 2006.
 //
 // Distributed under the Boost Software License, Version 1.0.
 //    (See accompanying file LICENSE_1_0.txt or copy at
@@ -21,10 +21,10 @@
 #include <fstream> // used for operator<< :( - gps
 #include <string>    // for (basic_string and) getline()
 #include <algorithm> // for std::min
-#include <cassert>
+#include <assert.h>  // <cassert> is sometimes macro-guarded :-(
 
 #include "boost/limits.hpp"
-#include "boost/dynamic_bitset.hpp"
+#include "boost/dynamic_bitset/dynamic_bitset.hpp"
 #include "boost/test/minimal.hpp"
 
 
@@ -33,7 +33,9 @@
 {
 #ifdef __BORLANDC__
   // Borland deduces Block as a const qualified type,
-  // and finds numeric_limits<Block> to be zero :(
+  // and thus finds numeric_limits<Block> to be zero :(
+  //  (though not directly relevant here, see also
+  //   lib issue 559)
   int block_width = sizeof(Block) * CHAR_BIT;
 #else
   int block_width = std::numeric_limits<Block>::digits;
@@ -83,14 +85,14 @@
   const Ch zero = s.widen('0');
   const Ch one  = s.widen('1');
 
-  return Tr::eq(c, one) || Tr::eq(c, zero) ;
+  return Tr::eq(c, one) || Tr::eq(c, zero);
 }
 template <typename Stream, typename Ch>
 bool is_white_space(const Stream & s, Ch c)
 {
   // NOTE: the using directive is to satisfy Borland 5.6.4
-  //       with its own library (STLport), which chokes
-  //       on std::isspace(c, loc) - gps
+  //       with its own library (STLport), which doesn't
+  //       like std::isspace(c, loc) - gps
   using namespace std;
   return isspace(c, s.getloc());
 }
@@ -112,25 +114,29 @@
 template <typename Bitset>
 struct bitset_test {
 
-  static void from_unsigned_long(std::size_t N, unsigned long num)
-  {
-    // initializes the first M bit position to the cooresponding bit
-    // values in val. M is the smaller of N and the width of unsigned
-    // long
+  typedef typename Bitset::block_type Block;
+  BOOST_STATIC_CONSTANT(int, bits_per_block = Bitset::bits_per_block);
 
-    // missing from the std?
-    //   if M < N then the remaining bit positions are initialized to zero
 
-    Bitset b(N, num);
-    BOOST_CHECK(b.size() == N);
+  static void from_unsigned_long(std::size_t sz, unsigned long num)
+  {
+    // An object of size N = sz is constructed:
+    // - the first M bit positions are initialized to the corresponding bit
+    //   values in num (M being the smaller of N and the width of unsigned
+    //   long)
+    //
+    // - if M < N remaining bit positions are initialized to zero
+
+    Bitset b(sz, num);
+    BOOST_CHECK(b.size() == sz);
 
     const std::size_t ulong_width = std::numeric_limits<unsigned long>::digits;
-    std::size_t M = (std::min)(N, ulong_width);
-    std::size_t I;
-    for (I = 0; I < M; ++I)
-      BOOST_CHECK(b[I] == nth_bit(num, I));
-    for (; I < N; ++I)
-      BOOST_CHECK(b[I] == 0);
+    std::size_t m = (std::min)(sz, ulong_width);
+    std::size_t i;
+    for (i = 0; i < m; ++i)
+      BOOST_CHECK(b.test(i) == nth_bit(num, i));
+    for ( ; i < sz; ++i)
+      BOOST_CHECK(b.test(i) == 0);
   }
 
   // from string
@@ -177,9 +183,6 @@
 
   }
 
-  typedef typename Bitset::block_type Block;
-  BOOST_STATIC_CONSTANT(int, bits_per_block = Bitset::bits_per_block);
-
   static void to_block_range(const Bitset & b /*, BlockOutputIterator result*/)
   {
     typedef typename Bitset::size_type size_type;
@@ -615,29 +618,35 @@
   // to_ulong()
   static void to_ulong(const Bitset& lhs)
   {
-    std::size_t N = lhs.size();
-    std::size_t n = std::numeric_limits<unsigned long>::digits;
+    typedef unsigned long result_type;
+    std::size_t n = std::numeric_limits<result_type>::digits;
+    std::size_t sz = lhs.size();
+
     bool will_overflow = false;
-    for (std::size_t I = n; I < N; ++I)
-      if (lhs[I] != 0)
+    for (std::size_t i = n; i < sz; ++i) {
+      if (lhs.test(i) != 0) {
         will_overflow = true;
+        break;
+      }
+    }
     if (will_overflow) {
       try {
         (void)lhs.to_ulong();
         BOOST_CHECK(false); // It should have thrown an exception
-      } catch (std::overflow_error) {
+      } catch (std::overflow_error & ex) {
         // Good!
+        BOOST_CHECK(!!ex.what());
       } catch (...) {
         BOOST_CHECK(false); // threw the wrong exception
       }
     } else {
-      unsigned long num = lhs.to_ulong();
-      // Make sure the number is right
-      if (N == 0)
+      result_type num = lhs.to_ulong();
+      // Be sure the number is right
+      if (sz == 0)
         BOOST_CHECK(num == 0);
       else {
-        for (std::size_t I = 0; I < N; ++I)
-          BOOST_CHECK(lhs[I] == (I < n ? nth_bit(num, I) : 0)); //G.P.S. bugfix
+        for (std::size_t i = 0; i < sz; ++i)
+          BOOST_CHECK(lhs[i] == (i < n ? nth_bit(num, i) : 0)); //G.P.S. bugfix
       }
     }
   }
@@ -655,11 +664,11 @@
   static void count(const Bitset& b)
   {
     std::size_t c = b.count();
-    std::size_t c_real = 0;
-    for (std::size_t I = 0; I < b.size(); ++I)
-      if (b[I])
-        ++c_real;
-    BOOST_CHECK(c == c_real);
+    std::size_t actual = 0;
+    for (std::size_t i = 0; i < b.size(); ++i)
+      if (b[i])
+        ++actual;
+    BOOST_CHECK(c == actual);
   }
 
   static void size(const Bitset& b)
@@ -669,47 +678,82 @@
 
   static void any(const Bitset& b)
   {
-    BOOST_CHECK(b.any() == (b.count() > 0));
+    //BOOST_CHECK(b.any() == (b.count() > 0));
+    bool result = false;
+    for(std::size_t i = 0; i < b.size(); ++i)
+      if(b[i]) {
+        result = true;
+        break;
+      }
+    BOOST_CHECK(b.any() == result);
   }
 
   static void none(const Bitset& b)
   {
+    bool result = true;
+    for(std::size_t i = 0; i < b.size(); ++i) {
+      if(b[i]) {
+        result = false;
+        break;
+      }
+    }
+    BOOST_CHECK(b.none() == result);
+
+    // sanity
+    BOOST_CHECK(b.none() == !b.any());
     BOOST_CHECK(b.none() == (b.count() == 0));
   }
 
   static void subset(const Bitset& a, const Bitset& b)
   {
-    if (a.is_subset_of(b)) {
-      for (std::size_t I = 0; I < a.size(); ++I)
-        if (a[I])
-          BOOST_CHECK(b[I]);
-    } else {
-      bool is_subset = true;
-      for (std::size_t I = 0; I < a.size(); ++I)
-        if (a[I] && !b[I]) {
+    BOOST_CHECK(a.size() == b.size()); // PRE
+
+    bool is_subset = true;
+    if (b.size()) { // could use b.any() but let's be safe
+      for(std::size_t i = 0; i < a.size(); ++i) {
+        if(a.test(i) && !b.test(i)) {
           is_subset = false;
           break;
         }
-      BOOST_CHECK(is_subset == false);
+      }
     }
+    else {
+      // sanity
+      BOOST_CHECK(a.count() == 0);
+      BOOST_CHECK(a.any() == false);
+
+      //is_subset = (a.any() == false);
+    }
+
+    BOOST_CHECK(a.is_subset_of(b) == is_subset);
   }
 
   static void proper_subset(const Bitset& a, const Bitset& b)
   {
-    if (a.is_proper_subset_of(b)) {
-      for (std::size_t I = 0; I < a.size(); ++I)
-        if (a[I])
-          BOOST_CHECK(b[I]);
-      BOOST_CHECK(a.count() < b.count());
-    } else {
-      bool is_subset = true;
-      for (std::size_t I = 0; I < a.size(); ++I)
-        if (a[I] && !b[I]) {
-          is_subset = false;
-          break;
+    // PRE: a.size() == b.size()
+    BOOST_CHECK(a.size() == b.size());
+
+    bool is_proper = false;
+
+    if (b.size() != 0) {
+
+      // check it's a subset
+      subset(a, b);
+
+      // is it proper?
+      for (std::size_t i = 0; i < a.size(); ++i) {
+        if (!a.test(i) && b.test(i)) {
+          is_proper = true;
+          // sanity
+          BOOST_CHECK(a.count() < b.count());
+          BOOST_CHECK(b.any());
         }
-      BOOST_CHECK(is_subset == false || a.count() >= b.count());
+      }
     }
+
+    BOOST_CHECK(a.is_proper_subset_of(b) == is_proper);
+    if (is_proper)
+      BOOST_CHECK(b.is_proper_subset_of(a) != is_proper);// antisymmetry
   }
 
   static void intersects(const Bitset& a, const Bitset& b)
@@ -722,7 +766,7 @@
         have_intersection = true;
 
     BOOST_CHECK(a.intersects(b) == have_intersection);
-    // also check it is commutative
+    // also check commutativity
     BOOST_CHECK(b.intersects(a) == have_intersection);
   }
 


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to