diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/common/bitfield.py | 41 |
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.""" |