mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibCompress: Add unit tests for CanonicalCode.
This commit is contained in:
parent
5c9c0082a1
commit
3c03ce0c80
1 changed files with 43 additions and 0 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include <AK/TestSuite.h>
|
#include <AK/TestSuite.h>
|
||||||
|
|
||||||
#include <AK/Array.h>
|
#include <AK/Array.h>
|
||||||
|
#include <AK/MemoryStream.h>
|
||||||
#include <LibCompress/Deflate.h>
|
#include <LibCompress/Deflate.h>
|
||||||
#include <LibCompress/Gzip.h>
|
#include <LibCompress/Gzip.h>
|
||||||
#include <LibCompress/Zlib.h>
|
#include <LibCompress/Zlib.h>
|
||||||
|
@ -44,6 +45,48 @@ static bool compare(ReadonlyBytes lhs, ReadonlyBytes rhs)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(canonical_code_simple)
|
||||||
|
{
|
||||||
|
const Array<u8, 32> code {
|
||||||
|
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
|
||||||
|
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
|
||||||
|
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05
|
||||||
|
};
|
||||||
|
const Array<u8, 6> input {
|
||||||
|
0x00, 0x42, 0x84, 0xa9, 0xb0, 0x15
|
||||||
|
};
|
||||||
|
const Array<u32, 9> output {
|
||||||
|
0x00, 0x01, 0x01, 0x02, 0x03, 0x05, 0x08, 0x0d, 0x15
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto huffman = Compress::CanonicalCode::from_bytes(code).value();
|
||||||
|
auto memory_stream = InputMemoryStream { input };
|
||||||
|
auto bit_stream = InputBitStream { memory_stream };
|
||||||
|
|
||||||
|
for (size_t idx = 0; idx < 9; ++idx)
|
||||||
|
EXPECT_EQ(huffman.read_symbol(bit_stream), output[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(canonical_code_complex)
|
||||||
|
{
|
||||||
|
const Array<u8, 6> code {
|
||||||
|
0x03, 0x02, 0x03, 0x03, 0x02, 0x03
|
||||||
|
};
|
||||||
|
const Array<u8, 4> input {
|
||||||
|
0xa1, 0xf3, 0xa1, 0xf3
|
||||||
|
};
|
||||||
|
const Array<u32, 12> output {
|
||||||
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto huffman = Compress::CanonicalCode::from_bytes(code).value();
|
||||||
|
auto memory_stream = InputMemoryStream { input };
|
||||||
|
auto bit_stream = InputBitStream { memory_stream };
|
||||||
|
|
||||||
|
for (size_t idx = 0; idx < 12; ++idx)
|
||||||
|
EXPECT_EQ(huffman.read_symbol(bit_stream), output[idx]);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_CASE(deflate_decompress_compressed_block)
|
TEST_CASE(deflate_decompress_compressed_block)
|
||||||
{
|
{
|
||||||
const Array<u8, 28> compressed {
|
const Array<u8, 28> compressed {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue