def test_multiple(self): bc = BitConsumer(io.BytesIO(b"\xf0\xf0")) self.assertEqual(bc.u_get(3), 0b111) self.assertEqual(bc.u_get(2), 0b10) self.assertEqual(bc.u_get(1), 0b0) self.assertEqual(bc.u_get(5), 0b00111) self.assertEqual(bc.u_get(3), 0b100) self.assertEqual(bc.u_get(2), 0b00)
def test_fixedbit(self): bc = BitConsumer(io.BytesIO(b"\x70\xbb\xc3\xd7\x00")) self.assertEqual(bc.fb_get(17), 0.8807220458984375) self.assertEqual(bc.fb_get(16), -0.470001220703125)
def test_signed(self): bc = BitConsumer(io.BytesIO(b"\x7b\xf8")) self.assertEqual(bc.s_get(0), None) self.assertEqual(bc.s_get(4), 7) self.assertEqual(bc.s_get(10), -258)
def test_no_bits(self): bc = BitConsumer(io.BytesIO(b"\x01")) self.assertEqual(bc.u_get(0), None)
def test_short_bin(self): bc = BitConsumer(io.BytesIO(b"\x01")) self.assertEqual(bc.u_get(4), 0) self.assertEqual(bc.u_get(4), 1)
def test_exact_limit_next(self): bc = BitConsumer(io.BytesIO(b"\xf0\xf0\xf0")) v = bc.u_get(17) self.assertEqual(v, 0b11110000111100001)
def test_big(self): bc = BitConsumer(io.BytesIO(b"\xf0\xf0")) v = bc.u_get(12) self.assertEqual(v, 0b111100001111)
def test_get_from_left(self): bc = BitConsumer(io.BytesIO(b"\xf0")) v = bc.u_get(6) self.assertEqual(v, 0b111100)
def test_simple(self): bc = BitConsumer(io.BytesIO(b"\xff")) v = bc.u_get(5) self.assertEqual(v, 0x1f)
def test_exact_limit_prev(self): bc = BitConsumer(io.BytesIO(b"\xf0\xf0\xf0")) v = bc.u_get(15) self.assertEqual(v, 0b111100001111000)