1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

add unit tests for map block position encoding

This commit is contained in:
Erich Schubert 2025-03-01 18:27:57 +01:00 committed by sfan5
parent 42ac5b2f40
commit c439d784ac

View file

@ -72,6 +72,7 @@ public:
void testLoad();
void testList(int expect);
void testRemove();
void testPositionEncoding();
private:
MapDatabaseProvider *provider = nullptr;
@ -90,6 +91,8 @@ void TestMapDatabase::runTests(IGameDef *gamedef)
test_data.push_back(static_cast<char>(c));
sanity_check(!test_data.empty());
TEST(testPositionEncoding);
rawstream << "-------- Dummy" << std::endl;
// We can't re-create this object since it would lose the data
@ -193,3 +196,31 @@ void TestMapDatabase::testRemove()
// FIXME: this isn't working consistently, maybe later
//UASSERT(!db->deleteBlock({1, 2, 4}));
}
void TestMapDatabase::testPositionEncoding()
{
auto db = std::make_unique<Database_Dummy>();
// Unit vectors and extremes
UASSERTEQ(s64, db->getBlockAsInteger({0, 0, 0}), 0)
UASSERTEQ(s64, db->getBlockAsInteger({1, 0, 0}), 1)
UASSERTEQ(s64, db->getBlockAsInteger({0, 1, 0}), 0x1000)
UASSERTEQ(s64, db->getBlockAsInteger({0, 0, 1}), 0x1000000)
UASSERTEQ(s64, db->getBlockAsInteger({-1, 0, 0}), -1)
UASSERTEQ(s64, db->getBlockAsInteger({0, -1, 0}), -0x1000)
UASSERTEQ(s64, db->getBlockAsInteger({0, 0, -1}), -0x1000000)
UASSERTEQ(s64, db->getBlockAsInteger({2047, 2047, 2047}), 0x7FF7FF7FF)
UASSERTEQ(s64, db->getBlockAsInteger({-2048, -2048, -2048}), -0x800800800)
UASSERTEQ(s64, db->getBlockAsInteger({-123, 456, -789}), -0x314e3807b)
UASSERT(db->getIntegerAsBlock(0) == v3s16(0, 0, 0))
UASSERT(db->getIntegerAsBlock(1) == v3s16(1, 0, 0))
UASSERT(db->getIntegerAsBlock(0x1000) == v3s16(0, 1, 0))
UASSERT(db->getIntegerAsBlock(0x1000000) == v3s16(0, 0, 1))
UASSERT(db->getIntegerAsBlock(-1) == v3s16(-1, 0, 0))
UASSERT(db->getIntegerAsBlock(-0x1000) == v3s16(0, -1, 0))
UASSERT(db->getIntegerAsBlock(-0x1000000) == v3s16(0, 0, -1))
UASSERT(db->getIntegerAsBlock(0x7FF7FF7FF) == v3s16(2047, 2047, 2047))
UASSERT(db->getIntegerAsBlock(-0x800800800) == v3s16(-2048, -2048, -2048))
UASSERT(db->getIntegerAsBlock(-0x314e3807b) == v3s16(-123, 456, -789))
}