summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/common/bitfield.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/common/bitfield.py b/tests/common/bitfield.py
index 8c4a470..aff5de6 100644
--- a/tests/common/bitfield.py
+++ b/tests/common/bitfield.py
@@ -106,6 +106,19 @@ class TestBitFields(ChrysalideTestCase):
self.assertFalse(bf_a.test(67))
+ bf_a = BitField(75, 0)
+
+ bf_a.or_at(bf_b, 60)
+
+ self.assertFalse(bf_a.test(59))
+
+ self.assertTrue(bf_a.test(60))
+ self.assertTrue(bf_a.test(61))
+ self.assertFalse(bf_a.test(62))
+ self.assertTrue(bf_a.test(63))
+
+ self.assertFalse(bf_a.test(64))
+
def testBitFieldSwitch(self):
"""Switch various bits in bitfields."""
@@ -216,3 +229,57 @@ class TestBitFields(ChrysalideTestCase):
bf_b = BitField(9, 1)
self.assertNotEqual(bf_a, bf_b)
+
+
+ def testRealCase00(self):
+ """Test bits in bitfields against other bitfields in a real case (#02)."""
+
+ bf = BitField(128, 0)
+
+ for b in [ 0, 50, 54, 58, 66, 70, 98 ]:
+ bf.set(b, 1)
+
+ mask = BitField(128, 0)
+
+ for b in [ 0, 51 ]:
+ mask.set(b, 1)
+
+ self.assertFalse(bf.test_zeros_with(0, mask))
+
+ self.assertTrue(bf.test_zeros_with(1, mask))
+
+ bf = BitField(32, 0)
+
+ mask = BitField(32, 0)
+
+ self.assertTrue(bf.test_zeros_with(0, mask))
+
+ for b in [ 0, 8, 9, 10 ]:
+ mask.set(b, 1)
+
+ self.assertTrue(bf.test_zeros_with(0, mask))
+
+ bf = BitField(32, 1)
+
+ self.assertFalse(bf.test_zeros_with(0, mask))
+
+ self.assertTrue(bf.test_ones_with(0, mask))
+
+
+ def testRealCase01(self):
+ """Test bits in bitfields against other bitfields in a real case (#01)."""
+
+ bf = BitField(128, 0)
+
+ mask = BitField(128, 0)
+
+ bits = [ 0, 50, 54, 58, 66, 70, 98 ]
+
+ for b in bits:
+ mask.set(b, 1)
+
+ bf.or_at(mask, 0)
+
+ self.assertEqual(mask.popcount, len(bits))
+
+ self.assertEqual(mask.popcount, bf.popcount)