stuff-from-scratch/test/compression/TestStreamCompressor.cpp
2022-11-23 15:41:33 +00:00

69 lines
1.5 KiB
C++

#include <iostream>
#include "BufferBitStream.h"
#include "HuffmanEncoder.h"
#include "RunLengthEncoder.h"
#include "Lz77Encoder.h"
void test_run_length_encoder()
{
std::string test_data = "BCAAAADDDCCACACAC";
RunLengthEncoder encoder;
auto encoded = encoder.encode(test_data);
std::cout << "Encoded: " << encoded << std::endl;
auto decoded = encoder.decode(encoded);
std::cout << "Decoded: " << decoded << std::endl;
}
void test_huffman_encoder()
{
//std::string testData = "BCAADDDCCACACAC";
//std::vector<unsigned char> stream(testData.begin(), testData.end());
std::unordered_map<unsigned char, unsigned> counts;
counts['A'] = 1;
counts['B'] = 1;
counts['C'] = 1;
counts['D'] = 2;
counts['E'] = 3;
counts['F'] = 5;
counts['G'] = 5;
counts['H'] = 12;
HuffmanEncoder encoder;
encoder.encode(counts);
}
void test_lz77_encoder()
{
std::string test_data = "sir sid eastman easily teases sea sick seals";
//std::string test_data = "sir sid eastman";
BufferBitStream input_stream;
input_stream.setBuffer(StringUtils::toBytes(test_data));
BufferBitStream output_stream;
Lz77Encoder encoder(&input_stream, &output_stream);
encoder.encode();
std::cout << "Encoded: " << StringUtils::toString(output_stream.getBuffer()) << std::endl;
//auto decoded = encoder.decode(encoded);
//std::cout << "Decoded: " << decoded << std::endl;
}
int main()
{
//test_huffman_encoder();
//test_run_length_encoder();
test_lz77_encoder();
return 0;
}