Ejemplo n.º 1
0
 def test_decompress_3(self):
     """ Decompress string that ends with repeated sequence:
     service byte: 00000001"""
     b_array = bytearray([1]) + bytearray(b'abcdefg') + bytearray([0, 99])
     actual = LZ77.decompress(b_array)
     expected = 'abcdefgabcde'
     self.assertEqual(actual, expected)
Ejemplo n.º 2
0
 def test_decompress_offset_less_len2(self):
     """ Decompress string that has repeated sequences where offset
     is less then sequence lenth """
     b_array = bytearray([8]) + bytearray(b'abcd') + bytearray([0, 52])
     actual = LZ77.decompress(b_array)
     expected = 'abcdabcdab'
     self.assertEqual(actual, expected)
Ejemplo n.º 3
0
 def test_decompress_2(self):
     """ Decompress string that has 2 repeated sequences """
     b_array = bytearray([3]) + bytearray(b'abcdef')\
                + bytearray([0, 32]) + bytearray([0, 113])
     actual = LZ77.decompress(b_array)
     expected = 'abcdefdeabc'
     self.assertEqual(actual, expected)
Ejemplo n.º 4
0
 def test_decompress_seq_diff_9_char(self):
     """ Decompress string of 9 char (2 service bytes) """
     b_array = bytearray([0]) + bytearray(b'12345678') \
                + bytearray([0]) + bytearray(b'9')
     actual = LZ77.decompress(b_array)
     expected = '123456789'
     self.assertEqual(actual, expected)
Ejemplo n.º 5
0
 def test_decompress_4(self):
     """ Decompress string that has repeated sequences at the begin of service_byte:
     service bytes: 00000000, 10000000 """
     b_array = bytearray([0]) + bytearray(b'abcdefgh')\
                + bytearray([128]) + bytearray([0, 84])
     actual = LZ77.decompress(b_array)
     expected = 'abcdefghcdefgh'
     self.assertEqual(actual, expected)
Ejemplo n.º 6
0
 def test_decompress_max_seq_len(self):
     """ Decompress string that has repeated sequence of max len (17) """
     a_int = ord('a')
     seq = ''.join(map(chr, range(a_int, a_int + LZ77.max_seq)))
     text = '123' + seq + '345' + seq
     b_array = bytearray([0]) + bytearray(text[:8], 'utf-8')\
                + bytearray([0]) + bytearray(text[8: 16], 'utf-8')\
                + bytearray([1]) + bytearray(text[16: 23], 'utf-8')\
                + bytearray([1, 63])
     actual = LZ77.decompress(b_array)
     expected = text
     self.assertEqual(actual, expected)
Ejemplo n.º 7
0
 def test_decompress_1(self):
     """ Decompress string that has repeated sequence """
     b_array = bytearray([8]) + bytearray(b'abcd') + bytearray([0, 49])
     actual = LZ77.decompress(b_array)
     expected = 'abcdabc'
     self.assertEqual(actual, expected)
Ejemplo n.º 8
0
 def test_decompress_seq_diff_8_char(self):
     """ Decompress string of 8 char (full 1 service byte) """
     b_array = bytearray([0]) + bytearray(b'12345678')
     actual = LZ77.decompress(b_array)
     expected = '12345678'
     self.assertEqual(actual, expected)
Ejemplo n.º 9
0
 def test_decompress_1_char(self):
     """ Decompress string of 1 char """
     b_array = bytearray([0]) + bytearray(b'a')
     actual = LZ77.decompress(b_array)
     expected = 'a'
     self.assertEqual(actual, expected)