add test for coders/rle
This commit is contained in:
parent
eedc3b2afb
commit
a18efd5976
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]);
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "voxels/Block.hpp"
|
||||
|
||||
TEST(Test1, Test1) {
|
||||
Block block("test");
|
||||
EXPECT_STREQ(block.name.c_str(), "test");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user