Skip to content

Commit c554df5

Browse files
committed
tests/extmod/deflate_compress.py: Add a test for optimal compression.
Signed-off-by: Damien George <damien@micropython.org>
1 parent 6ba57f7 commit c554df5

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎tests/extmod/deflate_compress.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,9 @@ def check_header(n, a, b):
146146
next_len = len(result)
147147
print(next_len < prev_len and decompress(result, deflate.RAW, wbits) == buf)
148148
prev_len = next_len
149+
150+
# Verify that compression is optimal: in the bytes below, the final "123" should be
151+
# compressed by referencing the "123" just before it, and not the one all the way back
152+
# at the start of the bytes.
153+
compressed = compress(b"1234567890abcdefghijklmnopqrstuvwxyz123123", deflate.RAW)
154+
print(len(compressed), compressed)

‎tests/extmod/deflate_compress.py.exp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ True
3939
True
4040
True
4141
True
42+
41 b'3426153\xb7\xb04HLJNIMK\xcf\xc8\xcc\xca\xce\xc9\xcd\xcb/(,*.)-+\xaf\xa8\xac\x02\xaa\x01"\x00'

0 commit comments

Comments
 (0)