Пример #1
0
 def test_flip_bit(self):
     bitmap = Bitmap(value=10)
     bitmap.flip_bit(2)
     bitmap.flip_bit(1)
     self.assertEqual(bitmap.get_bit(2), 1)
     self.assertEqual(bitmap.get_bit(1), 0)
     self.assertEqual(bitmap.value, 12)
Пример #2
0
 def test_invalid_i(self):
     bitmap = Bitmap(size=10, value=10)
     with self.assertRaises(TypeError):
         _ = bitmap.get_bit(2.0)  # type: ignore
     with self.assertRaises(TypeError):
         bitmap.set_bit('0b0010')  # type: ignore
     with self.assertRaises(TypeError):
         bitmap.clear_bit([2])  # type: ignore
     # i < 0
     with self.assertRaises(ValueError):
         bitmap.flip_bit(-1)
     # i >= size
     with self.assertRaises(ValueError):
         _ = bitmap.get_bit(10)