Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def test_bytestr_uncode_encode(self):
        hello = 'Привет'
        self.assertEqual(bytestr_encode(hello, encoding='utf-8'), 
            int_to_byte(len(hello.encode('utf-8'))) + hello.encode('utf-8'))

        long_hello = hello * 100
        self.assertEqual(bytestr_encode(long_hello, encoding='utf-8'), 
            uint_encode(len(long_hello.encode('utf-8')), n=7) + long_hello.encode('utf-8'))
Exemplo n.º 4
0
    def test_bytestr_uncode_encode(self):
        hello = 'Привет'
        self.assertEqual(
            bytestr_encode(hello, encoding='utf-8'),
            int_to_byte(len(hello.encode('utf-8'))) + hello.encode('utf-8'))

        long_hello = hello * 100
        self.assertEqual(
            bytestr_encode(long_hello, encoding='utf-8'),
            uint_encode(len(long_hello.encode('utf-8')), n=7) +
            long_hello.encode('utf-8'))
Exemplo n.º 5
0
 def test_decode_encoded_uint(self):
     self.assertEqual(uint_decode(uint_encode(187, n=5), n=5), 187)
     self.assertEqual(uint_decode(uint_encode(78, n=7), n=7), 78)
     self.assertEqual(uint_decode(uint_encode(1126)), 1126)
     self.assertEqual(uint_decode(uint_encode(26)), 26)
     self.assertEqual(uint_decode(uint_encode(2000, n=2), n=2), 2000)
Exemplo n.º 6
0
 def test_decode_encoded_uint(self):
     self.assertEqual(uint_decode(uint_encode(187, n=5), n=5), 187)
     self.assertEqual(uint_decode(uint_encode(78, n=7), n=7), 78)
     self.assertEqual(uint_decode(uint_encode(1126)), 1126)
     self.assertEqual(uint_decode(uint_encode(26)), 26)
     self.assertEqual(uint_decode(uint_encode(2000, n=2), n=2), 2000)