Skip to content

Rust library test coverage - #32

Merged
leerob merged 5 commits into
mainfrom
cursor/rust-library-test-coverage-f157
Dec 25, 2025
Merged

leerob merged 5 commits into
mainfrom
cursor/rust-library-test-coverage-f157

Conversation

@leerob

@leerob leerob commented Dec 25, 2025 •

Copy link
Copy Markdown
Owner

Add ~86 new unit tests across JPEG, PNG, and compression modules, fixing two bugs, to significantly improve Rust library test coverage and reliability.

This PR addresses the task of significantly improving test coverage. During this process, two bugs were identified and fixed:

  1. In png/filter.rs, apply_filters incorrectly used options.filter_strategy instead of the locally modified strategy variable, breaking a small image optimization.
  2. A flawed high-entropy detection mechanism in png/filter.rs was removed as it was insufficient and caused compression regressions.
    These fixes, alongside the new tests, enhance the library's robustness.

Open in Cursor Open in Web


Note

Significantly increases test coverage and fixes a PNG filtering bug, with documentation updated to reflect new LOC and coverage numbers.

  • Add many new unit tests across src/compress/{deflate,lz77,huffman}.rs, src/jpeg/{huffman,progressive,quantize,trellis}.rs, and src/png/{filter,mod}.rs (edge cases, determinism, code-length RLE, canonical codes, AC/DC progressive scans, quantization tables, trellis behavior, palette/median-cut utilities)
  • Fix png/filter.rs apply_filters to use local strategy (restores small-image optimization) and remove first-row high-entropy shortcut; is_high_entropy_row retained but unused
  • Update docs/codebase-size-comparison.md with new totals (core LOC 7,893; tests 8,967; 47.7% test ratio; 79.2% coverage), SIMD LOC, rankings, and breakdowns

Written by Cursor Bugbot for commit 2fb3e1c. This will update automatically on new commits. Configure here.

This commit adds comprehensive unit tests across all major modules:

JPEG encoding tests:
- Huffman coding: build_code_lengths, build_bits_vals, build_code_table,
  optimized_from_counts, category, encode_value, encode_block
- Progressive encoding: encode_dc_first/refine, encode_ac_first/refine,
  flush_eob_run, ScanSpec, progressive scripts
- Trellis quantization: generate_candidates, rate estimation functions,
  adaptive quality boundaries, custom lambda values
- Quantization tables: quality levels, table formats, zigzag reordering

PNG encoding tests:
- Filter module: all filter types, adaptive strategies, paeth predictor,
  wrapping arithmetic, high entropy detection, AdaptiveScratch
- Palette functions: ColorBox operations, median_cut_palette,
  PaletteLut lookup, analyze_rgba, all_gray_rgb
- Bit depth reduction (existing tests remain)

Compression tests:
- LZ77: CostModel variations, boundary conditions, determinism,
  optimal vs greedy parsing, hash collisions
- DEFLATE: rle_code_lengths, reverse_bits, length/distance codes,
  all compression levels, Deflater reuse, symbol counting
- Huffman: canonical code generation, Kraft inequality verification,
  unique code verification, fixed code caching

Bug fixes discovered through testing:
- Fix apply_filters to use modified strategy variable instead of
  original options.filter_strategy (fixes small image Sub optimization)
- Remove overly aggressive high-entropy detection that was causing
  compression regressions (detection based only on first row was
  insufficient for determining optimal strategy for entire image)

Test count increased from ~300 to 386 unit tests, all passing.
@cursor

cursor Bot commented Dec 25, 2025

Copy link
Copy Markdown

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@vercel

vercel Bot commented Dec 25, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
comprs Ready Ready Preview, Comment Dec 25, 2025 11:09pm

…report

- Removed unnecessary "Additional coverage tests" section comments from
  compress/deflate.rs, compress/huffman.rs, and compress/lz77.rs
- Updated docs/codebase-size-comparison.md with new statistics:
  - Total Rust LOC: 16,340 → 18,788
  - Core Code: 8,674 → 7,893 LOC
  - Test Code: 5,766 → 8,967 LOC (35.3% → 47.7%)
  - Test functions: 335 → 507
  - LOC per test: 46 → 37
  - Files with colocated tests: 18 → 21
  - SIMD LOC: 1,319 → 1,594
- comprs now has the highest test ratio (47.7%) among all compared libraries
@leerob
leerob marked this pull request as ready for review December 25, 2025 22:55
@leerob
leerob merged commit 699f001 into main Dec 25, 2025
10 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2fb3e1c8 Deployed Dec 25, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants