def test_keep_bitrange_range_exceeds_input_returns_zero(self): self.assertEqual(0, keep_bitrange(0xA, 9, 12))
def test_keep_bitrange_high_smaller_than_low_raises(self): with self.assertRaises(ValueError): keep_bitrange(0xABC, 2, 1)
def test_keep_bitrange_low_equal_high_keeps_single_bit(self): self.assertEqual(0x80, keep_bitrange(0xFAF, 8, 8))
def test_keep_bitrange_zero_low_raises(self): with self.assertRaises(ValueError): keep_bitrange(0xABC, 0, 1)
def test_keep_bitrange_negative_low_raises(self): with self.assertRaises(ValueError): keep_bitrange(0xABC, -1, 1)
def test_keep_bitrange_keep_last_bits(self): self.assertEqual(0xA, keep_bitrange(0xFFA, 1, 4))
def test_keep_bitrange_keep_first_bits(self): self.assertEqual(0xA00, keep_bitrange(0xAFF, 9, 12))
def test_keep_bitrange_keep_midle_bits(self): self.assertEqual(0xA0, keep_bitrange(0xFAF, 5, 8))