def test_byterepr_to_bytes(self): self.assertEqual(byterepr_to_bytes('00000000'), b'\x00') self.assertEqual(byterepr_to_bytes('00001111'), b'\x0f') self.assertEqual(byterepr_to_bytes('10101110'), b'\xae') self.assertEqual(byterepr_to_bytes( '00000000', '00001111', '10101110'), b'\x00\x0f\xae') self.assertEqual(byterepr_to_bytes(), b'')
def test_uint_encode(self): self.assertEqual(uint_encode(10, n=5), b'\x0a') self.assertEqual(uint_encode(1337, n=5), byterepr_to_bytes('00011111', '10011010', '00001010')) self.assertEqual(uint_encode(42), byterepr_to_bytes('00101010')) with self.assertRaises(ValueError): uint_encode(-42, n=5)
def test_uint_encode(self): self.assertEqual(uint_encode(10, n=5), b'\x0a') self.assertEqual(uint_encode(1337, n=5), byterepr_to_bytes( '00011111', '10011010', '00001010' )) self.assertEqual(uint_encode(42), byterepr_to_bytes('00101010')) with self.assertRaises(ValueError): uint_encode(-42, n=5)