Add test fixture.

This commit is contained in:
James Grogan 2022-11-29 18:00:19 +00:00
parent af6fad72eb
commit d6d4319e21
37 changed files with 421 additions and 279 deletions

View file

@ -1,9 +1,11 @@
#include <iostream>
#include "TestFramework.h"
#include "HuffmanStream.h"
#include "BufferBitStream.h"
void testHuffmanCodeLengthTable()
TEST_CASE(TestHuffmanCodeLengthTable, "compression")
{
HuffmanCodeLengthTable table;
@ -17,23 +19,23 @@ void testHuffmanCodeLengthTable()
}
}
table.setInputLengthSequence(code_length_sequence, false);
table.buildCompressedLengthSequence();
auto compressed_sequence = table.getCompressedLengthSequence();
for (auto entry : compressed_sequence)
{
std::cout << "Count " << entry.first << " extra bits " << entry.second << std::endl;
// std::cout << "Count " << entry.first << " extra bits " << entry.second << std::endl;
}
auto compressed_lengths = table.getCompressedLengthCounts();
for(unsigned idx = 0; idx<compressed_lengths.size(); idx++)
{
std::cout << "Slot " << idx << " length " << compressed_lengths[idx] << std::endl;
//std::cout << "Slot " << idx << " length " << compressed_lengths[idx] << std::endl;
}
}
};
void testLiteralsTable()
TEST_CASE(TestLiteralsTable, "compression")
{
std::vector<unsigned char> lengths = {7,4,4,7,5,5,7,7,6,6,7,6,6,6,8,6,6,8,
6,6,7,6,8,7,7,7,7,7,7,6,6,7,7,6,6,7,7,8,8,7,7,7,6,6,7,7,7,7,6,7,7,7,
@ -53,13 +55,13 @@ void testLiteralsTable()
auto compressed_sequence = table.getCompressedLengthSequence();
for (auto entry : compressed_sequence)
{
std::cout << "Code " << entry.first << " extra bits " << entry.second << std::endl;
// std::cout << "Code " << entry.first << " extra bits " << entry.second << std::endl;
}
auto compressed_lengths = table.getCompressedLengthCounts();
for(unsigned idx = 0; idx<compressed_lengths.size(); idx++)
{
std::cout << "Slot " << idx << " length " << compressed_lengths[idx] << std::endl;
// std::cout << "Slot " << idx << " length " << compressed_lengths[idx] << std::endl;
}
HuffmanCodeLengthTable codingTable;
@ -99,7 +101,6 @@ void testLiteralsTable()
{
out_stream.writeNBits(permuted[idx], 3);
}
*/
for(unsigned idx=0; idx<14;idx++)
{
@ -131,15 +132,15 @@ void testLiteralsTable()
std::cout << "Output is: " << std::endl;
auto dump = out_stream.logNextNBytes(out_stream.getBuffer().size());
std::cout << dump << std::endl;
}
*/
};
int main()
{
//int main()
//{
//testHuffmanCodeLengthTable();
testLiteralsTable();
// testLiteralsTable();
//HuffmanStream stream(nullptr, nullptr);
//stream.setCodeLengthAlphabetLengths({3, 3, 3, 3, 3, 2, 4, 4});
@ -148,7 +149,7 @@ int main()
//stream.buildCodeLengthMapping();
std::cout << "*******" << std::endl;
//std::cout << "*******" << std::endl;
//stream.setCodeLengthAlphabetLengths({4, 0, 6, 7, 3, 2, 4, 2, 7, 4, 6, 3, 0, 6});
//stream.buildCodeLengthMapping();
@ -157,6 +158,8 @@ int main()
//stream.generateFixedCodeMapping();
// testCodeConversions();
return 0;
}
// return 0;
//}

View file

@ -1,9 +1,12 @@
#include <iostream>
#include "Lz77Encoder.h"
#include "HuffmanEncoder.h"
#include "BufferBitStream.h"
int main()
#include "TestFramework.h"
TEST_CASE(TestLz77Encoder, "compression")
{
std::vector<unsigned> values {0, 10, 11, 12, 10, 11, 12, 0, 13, 14, 15, 10, 11, 12};
@ -28,5 +31,6 @@ int main()
std::cout << "Got hit " << length << " | " << distance << " | " << static_cast<int>(next_char) << std::endl;
}
return 0;
HuffmanEncoder huffman_encoder;
huffman_encoder.initializeTrees(hit_buffer);
}

View file

@ -5,21 +5,25 @@
#include "RunLengthEncoder.h"
#include "Lz77Encoder.h"
void test_run_length_encoder()
#include "StringUtils.h"
#include "TestFramework.h"
TEST_CASE(TestRunLengthEncoder, "compression")
{
std::string test_data = "BCAAAADDDCCACACAC";
RunLengthEncoder encoder;
auto encoded = encoder.encode(test_data);
auto encoded = encoder.encode(StringUtils::toBytes(test_data));
std::cout << "Encoded: " << encoded << std::endl;
//std::cout << "Encoded: " << encoded << std::endl;
auto decoded = encoder.decode(encoded);
std::cout << "Decoded: " << decoded << std::endl;
//std::cout << "Decoded: " << decoded << std::endl;
}
void test_huffman_encoder()
TEST_CASE(TestHuffmanEncoder, "compression")
{
//std::string testData = "BCAADDDCCACACAC";
//std::vector<unsigned char> stream(testData.begin(), testData.end());
@ -38,7 +42,7 @@ void test_huffman_encoder()
encoder.encode(counts);
}
void test_lz77_encoder()
TEST_CASE(TestLz77Encoder, "compression")
{
std::string test_data = "sir sid eastman easily teases sea sick seals";
//std::string test_data = "sir sid eastman";
@ -56,14 +60,3 @@ void test_lz77_encoder()
//std::cout << "Decoded: " << decoded << std::endl;
}
int main()
{
//test_huffman_encoder();
//test_run_length_encoder();
test_lz77_encoder();
return 0;
}