]> Savannah Git Hosting - gnulib.git/commitdiff
bitset: tests: check BITSET_FOR_EACH_REVERSE
authorAkim Demaille <akim.demaille@gmail.com>
Sat, 21 Nov 2020 13:11:34 +0000 (14:11 +0100)
committerAkim Demaille <akim.demaille@gmail.com>
Mon, 30 Nov 2020 05:44:28 +0000 (06:44 +0100)
* tests/test-bitset.c (compare, check_zero, check_one_bit, check_ones):
Check BITSET_FOR_EACH_REVERSE.

ChangeLog
tests/test-bitset.c

index c702e4458a7c0d030e26028a1b5d8e9f12ed58dd..2c34d92165a8e9ec7e9464c7ff9c333533d7d42a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-11-29  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: tests: check BITSET_FOR_EACH_REVERSE
+       * tests/test-bitset.c (compare, check_zero, check_one_bit, check_ones):
+       Check BITSET_FOR_EACH_REVERSE.
+
 2020-11-29  Bruno Haible  <bruno@clisp.org>
 
        spawn-pipe tests: Fix test failure with MSVC.
index 6fa656a22778b47c68a514fe755a4b8dfa2ab1ef..ab3abac133ffd10640d2e8862455ab7c4fa4ebd0 100644 (file)
@@ -200,6 +200,36 @@ compare (enum bitset_attr a, enum bitset_attr b)
       }
   }
 
+  /* FOR_EACH_REVERSE.  */
+  {
+    bitset_iterator iter;
+    bitset_bindex j;
+    bitset_bindex first = bitset_first (bdst);
+    bitset_bindex last  = bitset_last (bdst);
+    bool seen_first = false;
+    bool seen_last = false;
+    BITSET_FOR_EACH_REVERSE (iter, bdst, j, 0)
+      {
+        ASSERT (first <= j && j <= last);
+        ASSERT (bitset_test (bdst, j));
+        if (j == first)
+          seen_first = true;
+        if (j == last)
+          seen_last = true;
+      }
+    if (first == BITSET_BINDEX_MAX)
+      {
+        ASSERT (!seen_first);
+        ASSERT (!seen_last);
+      }
+    else
+      {
+        ASSERT (seen_first);
+        ASSERT (seen_last);
+      }
+  }
+
+
   /* resize.
 
      ARRAY bitsets cannot be resized.  */
@@ -247,6 +277,8 @@ check_zero (bitset bs)
     bitset_bindex i;
     BITSET_FOR_EACH (iter, bs, i, 0)
       ASSERT (0);
+    BITSET_FOR_EACH_REVERSE (iter, bs, i, 0)
+      ASSERT (0);
   }
 }
 
@@ -276,6 +308,9 @@ check_one_bit (bitset bs, int bitno)
     bitset_bindex i;
     BITSET_FOR_EACH (iter, bs, i, 0)
       ASSERT (i == bitno);
+
+    BITSET_FOR_EACH_REVERSE (iter, bs, i, 0)
+      ASSERT (i == bitno);
   }
 }
 
@@ -304,6 +339,10 @@ check_ones (bitset bs)
     bitset_bindex count = 0;
     BITSET_FOR_EACH (iter, bs, i, 0)
       ASSERT (i == count++);
+    ASSERT (count == size);
+    BITSET_FOR_EACH_REVERSE (iter, bs, i, 0)
+      ASSERT (i == --count);
+    ASSERT (count == 0);
   }
 }