From c554df57f618fb8c42fcd120ce227a425e44c4bc Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 29 Nov 2023 11:43:43 +1100 Subject: [PATCH] tests/extmod/deflate_compress.py: Add a test for optimal compression. Signed-off-by: Damien George --- tests/extmod/deflate_compress.py | 6 ++++++ tests/extmod/deflate_compress.py.exp | 1 + 2 files changed, 7 insertions(+) diff --git a/tests/extmod/deflate_compress.py b/tests/extmod/deflate_compress.py index 612af663e4..981a986cbf 100644 --- a/tests/extmod/deflate_compress.py +++ b/tests/extmod/deflate_compress.py @@ -146,3 +146,9 @@ for wbits in range(5, 10): next_len = len(result) print(next_len < prev_len and decompress(result, deflate.RAW, wbits) == buf) prev_len = next_len + +# Verify that compression is optimal: in the bytes below, the final "123" should be +# compressed by referencing the "123" just before it, and not the one all the way back +# at the start of the bytes. +compressed = compress(b"1234567890abcdefghijklmnopqrstuvwxyz123123", deflate.RAW) +print(len(compressed), compressed) diff --git a/tests/extmod/deflate_compress.py.exp b/tests/extmod/deflate_compress.py.exp index 5da70f491b..7b00fa3cb2 100644 --- a/tests/extmod/deflate_compress.py.exp +++ b/tests/extmod/deflate_compress.py.exp @@ -39,3 +39,4 @@ True True True True +41 b'3426153\xb7\xb04HLJNIMK\xcf\xc8\xcc\xca\xce\xc9\xcd\xcb/(,*.)-+\xaf\xa8\xac\x02\xaa\x01"\x00'