Esempio n. 1
0
 def test_unsigned_cases(self):
     test_cases = (
         (0, [0x0]),
         (42, [42]),
         (127, [0x7F]),
         (128, [0x80, 1]),
         (255, [0xFF, 1]),
         (0xFFFF, [0xFF, 0xFF, 0b11]),
     )
     for value, data in test_cases:
         expected_data = bytes(data)
         encoded_data = unsigned_leb128_encode(value)
         self.assertEqual(expected_data, encoded_data)
         decoded_value = unsigned_leb128_decode(iter(expected_data))
         self.assertEqual(value, decoded_value)
Esempio n. 2
0
 def test_unsigned_wiki_example(self):
     """ Test the wikipedia example """
     data = unsigned_leb128_encode(624485)
     self.assertEqual(bytes([0xE5, 0x8E, 0x26]), data)
     self.assertEqual(624485, unsigned_leb128_decode(iter(data)))
Esempio n. 3
0
 def test_invalid_unsigned_number(self):
     """ Test negative unsigned number """
     with self.assertRaises(ValueError):
         unsigned_leb128_encode(-13)