mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
add test for coders/rle
This commit is contained in:
parent
eedc3b2afb
commit
a18efd5976
2 changed files with 48 additions and 8 deletions
48
test/coders/rle.cpp
Normal file
48
test/coders/rle.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "typedefs.hpp"
|
||||
#include "coders/rle.hpp"
|
||||
|
||||
TEST(RLE, EncodeDecode) {
|
||||
const int initial_size = 50'000;
|
||||
uint8_t initial[initial_size];
|
||||
uint8_t next = rand();
|
||||
for (int i = 0; i < initial_size; i++) {
|
||||
initial[i] = next;
|
||||
if (rand() % 13 == 0) {
|
||||
next = rand();
|
||||
}
|
||||
}
|
||||
uint8_t encoded[initial_size * 2];
|
||||
auto encoded_size = rle::encode(initial, initial_size, encoded);
|
||||
uint8_t decoded[initial_size * 2];
|
||||
auto decoded_size = rle::decode(encoded, encoded_size, decoded);
|
||||
|
||||
EXPECT_EQ(decoded_size, initial_size);
|
||||
|
||||
for (int i = 0; i < decoded_size; i++) {
|
||||
EXPECT_EQ(decoded[i], initial[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ExtRLE, EncodeDecode) {
|
||||
const int initial_size = 50'000;
|
||||
uint8_t initial[initial_size];
|
||||
uint8_t next = rand();
|
||||
for (int i = 0; i < initial_size; i++) {
|
||||
initial[i] = next;
|
||||
if (rand() % 13 == 0) {
|
||||
next = rand();
|
||||
}
|
||||
}
|
||||
uint8_t encoded[initial_size * 2];
|
||||
auto encoded_size = extrle::encode(initial, initial_size, encoded);
|
||||
uint8_t decoded[initial_size * 2];
|
||||
auto decoded_size = extrle::decode(encoded, encoded_size, decoded);
|
||||
|
||||
EXPECT_EQ(decoded_size, initial_size);
|
||||
|
||||
for (int i = 0; i < decoded_size; i++) {
|
||||
EXPECT_EQ(decoded[i], initial[i]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue