summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2022-12-07 02:52:51 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2022-12-07 02:52:51 (GMT)
commit6dea5e4fed979cb57f3dbc0c9144f1ff1854b800 (patch)
tree7d36f810bc15e8ceb5a994396a0734dfb91015e4 /tests
parent430aad874900f525c67a5aa5de9e6012a64ff603 (diff)
Provide functions to test bit fields against bit fields.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/bitfield.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/common/bitfield.py b/tests/common/bitfield.py
index e014111..7359a8a 100644
--- a/tests/common/bitfield.py
+++ b/tests/common/bitfield.py
@@ -118,6 +118,47 @@ class TestBitFields(ChrysalideTestCase):
self.assertTrue(bf.test_none(0, 54))
+ def testBitFieldWithBitField(self):
+ """Test bits in bitfields against other bitfields."""
+
+ bf = BitField(32, 0)
+ bf.set(8, 16)
+
+ mask = BitField(8, 1)
+
+ self.assertTrue(bf.test_ones_with(8, mask))
+ self.assertTrue(bf.test_ones_with(16, mask))
+ self.assertFalse(bf.test_ones_with(17, mask))
+ self.assertTrue(bf.test_zeros_with(24, mask))
+
+ bf = BitField(256, 0)
+ bf.set(60, 8)
+ bf.set(126, 10)
+
+ mask = BitField(4, 1)
+
+ self.assertTrue(bf.test_zeros_with(8, mask))
+ self.assertTrue(bf.test_zeros_with(122, mask))
+
+ self.assertFalse(bf.test_zeros_with(58, mask))
+ self.assertFalse(bf.test_ones_with(58, mask))
+ self.assertTrue(bf.test_ones_with(60, mask))
+ self.assertFalse(bf.test_zeros_with(63, mask))
+ self.assertTrue(bf.test_ones_with(64, mask))
+ self.assertFalse(bf.test_zeros_with(65, mask))
+ self.assertFalse(bf.test_ones_with(65, mask))
+
+ self.assertFalse(bf.test_zeros_with(125, mask))
+ self.assertFalse(bf.test_ones_with(125, mask))
+ self.assertTrue(bf.test_ones_with(128, mask))
+ self.assertFalse(bf.test_zeros_with(129, mask))
+ self.assertTrue(bf.test_ones_with(132, mask))
+ self.assertFalse(bf.test_zeros_with(133, mask))
+ self.assertFalse(bf.test_ones_with(133, mask))
+
+ self.assertTrue(bf.test_zeros_with(136, mask))
+
+
def testPopCountForBitField(self):
"""Count bits set to 1 in bitfield."""