[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/6] bitset: check empty and full bitsets
From: |
Akim Demaille |
Subject: |
[PATCH 2/6] bitset: check empty and full bitsets |
Date: |
Thu, 19 Nov 2020 07:01:51 +0100 |
* tests/test-bitset.c (check_zero, check_ones): New.
(check_attributes): Use them.
---
ChangeLog | 6 +++++
tests/test-bitset.c | 56 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 88ae15003..5badf0c41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-11-19 Akim Demaille <akim@lrde.epita.fr>
+
+ bitset: check empty and full bitsets
+ * tests/test-bitset.c (check_zero, check_ones): New.
+ (check_attributes): Use them.
+
2020-11-19 Akim Demaille <akim@lrde.epita.fr>
bitset: be sure to always return a value
diff --git a/tests/test-bitset.c b/tests/test-bitset.c
index 5068ae782..fc0c6fbe9 100644
--- a/tests/test-bitset.c
+++ b/tests/test-bitset.c
@@ -224,12 +224,37 @@ void compare (enum bitset_attr a, enum bitset_attr b)
}
+/* Check empty bitsets. */
+
+static void
+check_zero (bitset bs)
+{
+ fprintf (stderr, "check_zero\n");
+ bitset_zero (bs);
+
+ /* count. */
+ ASSERT (bitset_count (bs) == 0);
+
+ /* first and last */
+ ASSERT (bitset_first (bs) == BITSET_BINDEX_MAX);
+ ASSERT (bitset_last (bs) == BITSET_BINDEX_MAX);
+
+ /* FOR_EACH. */
+ {
+ bitset_iterator iter;
+ bitset_bindex i;
+ BITSET_FOR_EACH (iter, bs, i, 0)
+ ASSERT (0);
+ }
+}
+
/* Exercise on a single-bit values: it's easy to get the handling of
the most significant bit wrong. */
static void
check_one_bit (bitset bs, int bitno)
{
+ fprintf (stderr, "check_one_bit(%d)\n", bitno);
bitset_zero (bs);
bitset_set (bs, bitno);
@@ -252,6 +277,34 @@ check_one_bit (bitset bs, int bitno)
}
}
+/* Check full bitsets. */
+
+static void
+check_ones (bitset bs)
+{
+ fprintf (stderr, "check_ones\n");
+ const bitset_bindex size = bitset_size (bs);
+
+ bitset_ones (bs);
+ debug_bitset (bs);
+
+ /* count. */
+ ASSERT (bitset_count (bs) == size);
+
+ /* first and last */
+ ASSERT (bitset_first (bs) == 0);
+ ASSERT (bitset_last (bs) == size - 1);
+
+ /* FOR_EACH. */
+ {
+ bitset_iterator iter;
+ bitset_bindex i;
+ bitset_bindex count = 0;
+ BITSET_FOR_EACH (iter, bs, i, 0)
+ ASSERT (i == count++);
+ }
+}
+
/* Check various operations against expected values for a bitset
having attributes ATTR. */
@@ -287,6 +340,9 @@ check_attributes (enum bitset_attr attr, int nbits)
bitset_or (bs, bs1, bs2);
ASSERT (bitset_count (bs) == 6);
+ check_zero (bs);
+ check_ones (bs);
+
/* Exercise on all the single-bit values: it's easy to get the
handling of the most significant bit wrong. */
for (int bitno = 0; bitno < nbits; ++bitno)
--
2.29.2
- [PATCH 0/6] bitset: more conversions to ffs, Akim Demaille, 2020/11/19
- [PATCH 1/6] bitset: be sure to always return a value, Akim Demaille, 2020/11/19
- [PATCH 2/6] bitset: check empty and full bitsets,
Akim Demaille <=
- [PATCH 3/6] bitset: use ffs where possible in the table implementation, Akim Demaille, 2020/11/19
- [PATCH 4/6] bitset: use ffs where possible in the vector implementation, Akim Demaille, 2020/11/19
- [PATCH 5/6] bitset: tests: try harder to break it, Akim Demaille, 2020/11/19
- [PATCH 6/6] bitset: exercise the stats too, Akim Demaille, 2020/11/19
- [PATCH 6/6] bitset: tests: exercise the stats too, Akim Demaille, 2020/11/19
- Re: [PATCH 0/6] bitset: more conversions to ffs, Bruno Haible, 2020/11/19