Skip to content

Two unit tests assert compression ratio on inputs too small to compress #1

Description

@abhicris

Summary

Running cargo test --features zstd on a clean checkout of main produces two test failures:

failures:
    algorithms::enhanced_ctw::tests::test_enhanced_ctw_basic
    algorithms::multi_pass::tests::test_multi_pass_basic

test result: FAILED. 10 passed; 2 failed; 0 ignored

Both failures come from the same shape of assertion:

assert!(compressed.len() < test_data.len());

on inputs that are too small / too non-repetitive for the algorithm's framing overhead to pay for itself.

test_enhanced_ctw_basic

Input: b"Hello, world! This is a test of Enhanced CTW compression." (58 bytes). At this size the compressed stream header dominates. The roundtrip correctness assertion that precedes it passes; only the size assertion fails.

test_multi_pass_basic

Input: b"AAAA BBBB CCCC AAAA BBBB CCCC".repeat(10) (290 bytes). MultiPassCompressor::apply_pattern_replacement compares data[pos..pos+4] with data[pos+4..pos+8] (immediately-adjacent 4-byte blocks), which this input never contains. With best_ratio initialized to 1.0, the first pass shows no improvement and the method returns the original bytes unchanged, so compressed.len() == test_data.len() and the assertion fails. There is also no roundtrip assertion at all in this test.

Proposed fix

Small, scoped test-only change:

  • test_enhanced_ctw_basic: use a larger, more compressible corpus (e.g. repeat the sentence enough times that compression is plausible). Keep the existing roundtrip assertion.
  • test_multi_pass_basic: switch to input with immediately-repeated 4-byte blocks (e.g. b"AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD".repeat(N)) so apply_pattern_replacement can actually compress, and drop the assertion or guard it behind a roundtrip once decompress is implemented. For now, assert a ratio on the pass that produces a real output.

Happy to send a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions