[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
- [PATCH 0/7] bitset: use integrer_length in reverse iterations, Akim Demaille, 2020/11/29
- [PATCH 1/7] bitset: tests: check BITSET_FOR_EACH_REVERSE,
Akim Demaille <=
- [PATCH 2/7] bitset: style: sort header, Akim Demaille, 2020/11/29
- [PATCH 3/7] bitset: style: use consistent names, Akim Demaille, 2020/11/29
- [PATCH 4/7] bitset: use integrer_length in array implementation, Akim Demaille, 2020/11/29
- [PATCH 5/7] bitset: use integrer_length in vector implementation, Akim Demaille, 2020/11/29
- [PATCH 6/7] bitset: use integrer_length in list implementation, Akim Demaille, 2020/11/29
- [PATCH 7/7] bitset: use integrer_length in table implementation, Akim Demaille, 2020/11/29