test: fix compression-size assertions on too-small inputs#2
Open
abhicris wants to merge 1 commit into
Open
Conversation
`test_enhanced_ctw_basic` and `test_multi_pass_basic` asserted `compressed.len() < test_data.len()` on inputs so small that stream framing overhead made the check fail against a correct implementation. - enhanced_ctw: repeat the 58-byte input 32x so the zstd header is amortized and the compression-ratio assertion is meaningful. - multi_pass: switch to input with immediately-adjacent doubled 4-byte blocks so `apply_pattern_replacement` can actually compress on the first pass (matching `data[pos..pos+4] == data[pos+4..pos+8]`). Both roundtrip / size-reduction invariants now hold. All 25 tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two unit tests on
mainfail on a cleancargo test --features zstd:Both failed on the same assertion shape (
compressed.len() < test_data.len()) against inputs too small / too non-repetitive for the algorithm's framing overhead to pay for itself. The underlying implementations are correct -- the tests themselves were wrong.Fix
test_enhanced_ctw_basic: repeat the 58-byte input 32x so the zstd header is amortized and the ratio assertion is meaningful. Roundtrip assertion unchanged.test_multi_pass_basic: switch to input with immediately-adjacent doubled 4-byte blocks (AAAAAAAABBBBBBBB...) soapply_pattern_replacementcan actually compress on the first pass -- the previousAAAA BBBB CCCC ...input never matched thedata[pos..pos+4] == data[pos+4..pos+8]pattern and returned the original bytes unchanged.Test suite before:
23 passed, 2 failedTest suite after:
25 passed, 0 failedScope: 2 files, +25 -6 lines, tests only. No behavior changes to library code.
closes #1
Contributed by kcolbchain (https://kcolbchain.com) · https://abhishekkrishna.com