A Python script for illustrating the encoding and decoding of data using Huffman coding. This script can handle both text and binary files.
This project is a Python 3 implementation of the Huffman coding algorithm. It includes a script (huffman.py) that can be used to compress and decompress data. The script has been refactored for clarity and now includes comprehensive documentation and a test suite.
You can run the script from the command line. You can either provide a file as an argument for encoding or run it without arguments to use a default sample text.
To run the script with the default Lorem Ipsum text, simply execute:
python3 huffman.pyTo encode a specific file, provide the file path as a command-line argument:
python3 huffman.py [file_path]For example, to encode the provided testdata.html:
python3 huffman.py testdata.htmlA test suite is included to verify the functionality of the Huffman coding implementation. The tests cover various scenarios, including simple text, empty strings, and different file types.
To run the tests, execute the following command from the root directory:
python3 -m unittest test_huffman.pyYou should see an output indicating that all tests passed successfully.