62 lines
1.5 KiB
C++
62 lines
1.5 KiB
C++
#include <iostream>
|
|
|
|
#include "BufferBitStream.h"
|
|
#include "HuffmanEncoder.h"
|
|
#include "RunLengthEncoder.h"
|
|
#include "Lz77Encoder.h"
|
|
|
|
#include "StringUtils.h"
|
|
|
|
#include "TestFramework.h"
|
|
|
|
TEST_CASE(TestRunLengthEncoder, "compression")
|
|
{
|
|
std::string test_data = "BCAAAADDDCCACACAC";
|
|
|
|
RunLengthEncoder encoder;
|
|
auto encoded = encoder.encode(StringUtils::toBytes(test_data));
|
|
|
|
//std::cout << "Encoded: " << encoded << std::endl;
|
|
|
|
auto decoded = encoder.decode(encoded);
|
|
|
|
//std::cout << "Decoded: " << decoded << std::endl;
|
|
}
|
|
|
|
TEST_CASE(TestHuffmanEncoder, "compression")
|
|
{
|
|
//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);
|
|
}
|
|
|
|
TEST_CASE(TestLz77Encoder, "compression")
|
|
{
|
|
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;
|
|
}
|