stuff-from-scratch/test/compression/TestStreamCompressor.cpp

65 lines
1.3 KiB
C++
Raw Normal View History

2022-08-01 15:14:14 +00:00
#include <iostream>
#include "HuffmanEncoder.h"
2022-11-21 17:45:12 +00:00
#include "RunLengthEncoder.h"
#include "Lz77Encoder.h"
2022-08-01 15:14:14 +00:00
2022-11-21 17:45:12 +00:00
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()
2022-08-01 15:14:14 +00:00
{
2022-11-21 17:45:12 +00:00
//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;
2022-08-01 15:14:14 +00:00
2022-11-21 17:45:12 +00:00
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";
Lz77Encoder encoder;
auto encoded = encoder.encode(test_data);
2022-11-21 17:45:12 +00:00
std::cout << "Encoded: " << encoded << std::endl;
//auto decoded = encoder.decode(encoded);
//std::cout << "Decoded: " << decoded << std::endl;
2022-11-21 17:45:12 +00:00
}
2022-11-21 17:45:12 +00:00
int main()
{
//test_huffman_encoder();
2022-08-01 15:14:14 +00:00
2022-11-21 17:45:12 +00:00
//test_run_length_encoder();
test_lz77_encoder();
2022-08-01 15:14:14 +00:00
return 0;
}