Fix Huffman edge cases and add CMake tests#4
Open
cynricfu wants to merge 1 commit into
Open
Conversation
- Handle empty and single-symbol inputs; assign code "0" for one symbol - Use unsigned byte reads, validate non-ASCII input, and fix last-byte padding trim - Add destructor, I/O error handling, and safer decode with null checks - Add CMakeLists.txt, CTest roundtrip script, and README build instructions Co-authored-by: Xinyu Fu <fu.xinyu@outlook.com>
Owner
Author
|
This is just for trying out the cursor cloud agent. |
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
This PR hardens the Huffman compressor/decompressor based on the earlier code review, and adds a reproducible build plus regression tests.
Fixes (priority order)
rootwhen only one symbol exists; reject empty input files with a clear error."0"so encode/decode round-trips work for one-character files.unsigned char, reject bytes>= 128(7-bit ASCII scope), and use binary mode consistently.binary_to_decimal(const std::string&),#include <cstdlib>,nullptr, andstd::in headers (nousing namespace stdin.h).node_arrayslots.Build & test
cmake -S . -B build -DCMAKE_CXX_COMPILER=g++ cmake --build build ctest --test-dir build --output-on-failuretests/run_tests.shcovers sample text round-trip, single/two-character files, DEL (0x7F), empty-file rejection, and non-ASCII rejection.Notes
"0"(previously broken).0–127to match the original 128-entry symbol table.