def test_varint_size(self): # Check each boundary of varint sizing sizes = { 2: 0x80, 3: 0x4000, 4: 0x200000, 5: 0x10000000, 6: 0x800000000L, 7: 0x40000000000L, 8: 0x2000000000000L, 9: 0x100000000000000L, 10: 0x8000000000000000L } for i in xrange(128): self.assertEquals(1, len(encode_one(i))) for size, value in sizes.items(): self.assertEquals(size - 1, len(encode_one(value - 1))) self.assertEquals(size, len(encode_one(value)))
def test_encode_decode_one(self): for i in xrange(2048): self.assertEquals(i, decode_one(encode_one(i)))
def test_encode_negative(self): # numbers 0..127 get encoded as a single byte with self.assertRaises(ValueError): encode_one(-1)
def test_encode_one(self): # numbers 0..127 get encoded as a single byte for i in xrange(128): self.assertEquals(chr(i), encode_one(i))