bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/7] bitset: tests: check BITSET_FOR_EACH_REVERSE


From: Akim Demaille
Subject: [PATCH 1/7] bitset: tests: check BITSET_FOR_EACH_REVERSE
Date: Sun, 29 Nov 2020 17:42:15 +0100

* tests/test-bitset.c (compare, check_zero, check_one_bit, check_ones):
Check BITSET_FOR_EACH_REVERSE.
---
 ChangeLog           |  6 ++++++
 tests/test-bitset.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index fa21e9cd2..67576a51f 100644
--- 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-28  Bruno Haible  <bruno@clisp.org>
 
        asyncsafe-spin: Fix compilation error with GCC on 32-bit SPARC.
diff --git a/tests/test-bitset.c b/tests/test-bitset.c
index 6fa656a22..ab3abac13 100644
--- a/tests/test-bitset.c
+++ b/tests/test-bitset.c
@@ -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);
   }
 }
 
-- 
2.29.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]