Ejemplo n.º 1
0
 def testTestBit(self):
     """Test testBit() method."""
     value = BitField(129)
     self.assertTrue(value.testBit(0), "Value is %s" % value)
     self.assertFalse(value.testBit(1), "Value is %s" % value)
     self.assertTrue(value.testBit(7), "Value is %s" % value)
     self.assertFalse(value.testBit(8), "Value is %s" % value)
Ejemplo n.º 2
0
 def testToInt(self):
     """Test toInt() method."""
     bitfield = BitField(65)
     self.assertTrue(isinstance(bitfield, BitField))
     i = bitfield.toInt()
     self.assertTrue(isinstance(i, int))
     self.assertTrue(i, 65)
Ejemplo n.º 3
0
 def testTestBits(self):
     """Test testBits() method."""
     value = BitField(15)
     self.assertTrue(value.testBits(7), "Value is %s" % value)
     self.assertFalse(value.testBits(24), "Value is %s" % value)
     self.assertTrue(value.testBits(15), "Value is %s" % value)
     self.assertFalse(value.testBits(31), "Value is %s" % value)
Ejemplo n.º 4
0
 def testMask(self):
     """Test mask() method."""
     m = BitField.mask(numBits=4)
     self.assertTrue(isinstance(m, BitField))
     self.assertEqual(m, 15, "mask value is %s" % m)
     m = BitField.mask(numBits=2, offset=3)
     self.assertEqual(m, 24, "mask value is %s" % m)
     m = BitField.mask(numBits=7, offset=1)
     self.assertEqual(m, 254, "mask value is %s" % m)
     m = BitField.mask(numBits=2, offset=10)
     self.assertEqual(m, 3072, "mask value is %s" % m)
Ejemplo n.º 5
0
 def testFilterBits(self):
     """Test filterBits() method."""
     value = BitField(255)
     self.assertEqual(value, 255, "Value is %s" % value)
     filtered = value.filterBits() # Should do nothing
     self.assertEqual(filtered, 255)
     filtered = value.filterBits(10) # Should do nothing
     self.assertEqual(filtered, 255)
     filtered = value.filterBits(5)
     self.assertEqual(filtered, 223)
     filtered = value.filterBits(3,2,1,0)
     self.assertEqual(filtered, 240)
Ejemplo n.º 6
0
 def testGetBitRange(self):
     """Test getBitRange() method."""
     value = BitField(15)
     self.assertEqual(value.getBitRange(numBits=3), 7)
     self.assertEqual(value.getBitRange(numBits=5, offset=3, shift=True), 1)
     self.assertEqual(value.getBitRange(numBits=2, offset=2, shift=True), 3)