2022-08-01 15:14:14 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-11-23 15:41:33 +00:00
|
|
|
#include "BufferBitStream.h"
|
2022-08-01 15:14:14 +00:00
|
|
|
#include "HuffmanEncoder.h"
|
2022-11-21 17:45:12 +00:00
|
|
|
#include "RunLengthEncoder.h"
|
2022-11-22 17:37:06 +00:00
|
|
|
#include "Lz77Encoder.h"
|
2022-08-01 15:14:14 +00:00
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
#include "StringUtils.h"
|
|
|
|
|
|
|
|
#include "TestFramework.h"
|
|
|
|
|
|
|
|
TEST_CASE(TestRunLengthEncoder, "compression")
|
2022-11-21 17:45:12 +00:00
|
|
|
{
|
2023-12-21 09:18:44 +00:00
|
|
|
String test_data = "BCAAAADDDCCACACAC";
|
2022-11-21 17:45:12 +00:00
|
|
|
|
|
|
|
RunLengthEncoder encoder;
|
2022-11-29 18:00:19 +00:00
|
|
|
auto encoded = encoder.encode(StringUtils::toBytes(test_data));
|
2022-11-21 17:45:12 +00:00
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
//std::cout << "Encoded: " << encoded << std::endl;
|
2022-11-21 17:45:12 +00:00
|
|
|
|
|
|
|
auto decoded = encoder.decode(encoded);
|
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
//std::cout << "Decoded: " << decoded << std::endl;
|
2022-11-21 17:45:12 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
TEST_CASE(TestHuffmanEncoder, "compression")
|
2022-08-01 15:14:14 +00:00
|
|
|
{
|
2023-12-21 09:18:44 +00:00
|
|
|
//String testData = "BCAADDDCCACACAC";
|
|
|
|
//Vector<unsigned char> stream(testData.begin(), testData.end());
|
2022-11-21 17:45:12 +00:00
|
|
|
|
2023-12-27 12:20:02 +00:00
|
|
|
Map<unsigned char, unsigned> counts;
|
2022-11-21 17:45:12 +00:00
|
|
|
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);
|
2022-11-22 17:37:06 +00:00
|
|
|
}
|
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
TEST_CASE(TestLz77Encoder, "compression")
|
2022-11-22 17:37:06 +00:00
|
|
|
{
|
2023-12-21 09:18:44 +00:00
|
|
|
String test_data = "sir sid eastman easily teases sea sick seals";
|
|
|
|
//String test_data = "sir sid eastman";
|
2022-11-22 17:37:06 +00:00
|
|
|
|
2022-11-23 15:41:33 +00:00
|
|
|
BufferBitStream input_stream;
|
|
|
|
input_stream.setBuffer(StringUtils::toBytes(test_data));
|
2022-11-21 17:45:12 +00:00
|
|
|
|
2022-11-23 15:41:33 +00:00
|
|
|
BufferBitStream output_stream;
|
|
|
|
Lz77Encoder encoder(&input_stream, &output_stream);
|
|
|
|
encoder.encode();
|
|
|
|
|
2022-11-30 18:28:50 +00:00
|
|
|
//std::cout << "Encoded: " << StringUtils::toString(output_stream.getBuffer()) << std::endl;
|
2022-11-22 17:37:06 +00:00
|
|
|
|
|
|
|
//auto decoded = encoder.decode(encoded);
|
|
|
|
|
|
|
|
//std::cout << "Decoded: " << decoded << std::endl;
|
2022-11-21 17:45:12 +00:00
|
|
|
}
|