aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_map.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-12-17 17:21:14 +0100
committersfan5 <sfan5@live.de>2022-01-30 13:49:26 +0100
commita9bccb964f6c6ffe9d4f84922d9be640e4dd2f1e (patch)
tree03d526445df226332c0c376f52957524c14a0d93 /src/unittest/test_map.cpp
parent74a384de0acd52410269d160e94f1705cb4de300 (diff)
downloadminetest-a9bccb964f6c6ffe9d4f84922d9be640e4dd2f1e.tar.gz
minetest-a9bccb964f6c6ffe9d4f84922d9be640e4dd2f1e.tar.bz2
minetest-a9bccb964f6c6ffe9d4f84922d9be640e4dd2f1e.zip
Raise max mapgen limit constant to align with mapblock size
Diffstat (limited to 'src/unittest/test_map.cpp')
-rw-r--r--src/unittest/test_map.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/unittest/test_map.cpp b/src/unittest/test_map.cpp
new file mode 100644
index 000000000..82e55e1aa
--- /dev/null
+++ b/src/unittest/test_map.cpp
@@ -0,0 +1,68 @@
+/*
+Minetest
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "test.h"
+
+#include <cstdio>
+#include "mapblock.h"
+
+class TestMap : public TestBase
+{
+public:
+ TestMap() { TestManager::registerTestModule(this); }
+ const char *getName() { return "TestMap"; }
+
+ void runTests(IGameDef *gamedef);
+
+ void testMaxMapgenLimit();
+};
+
+static TestMap g_test_instance;
+
+void TestMap::runTests(IGameDef *gamedef)
+{
+ TEST(testMaxMapgenLimit);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+void TestMap::testMaxMapgenLimit()
+{
+ // limit must end on a mapblock boundary
+ UASSERTEQ(int, MAX_MAP_GENERATION_LIMIT % MAP_BLOCKSIZE, MAP_BLOCKSIZE - 1);
+
+ // objectpos_over_limit should do exactly this except the last node
+ // actually spans from LIMIT-0.5 to LIMIT+0.5
+ float limit_times_bs = MAX_MAP_GENERATION_LIMIT * BS;
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs-BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs)) == false);
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS)) == true);
+
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs+BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs)) == false);
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS/2)) == false);
+ UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS)) == true);
+
+ // blockpos_over_max_limit
+ s16 limit_block = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
+ UASSERT(blockpos_over_max_limit(v3s16(limit_block)) == false);
+ UASSERT(blockpos_over_max_limit(v3s16(limit_block+1)) == true);
+ UASSERT(blockpos_over_max_limit(v3s16(-limit_block)) == false);
+ UASSERT(blockpos_over_max_limit(v3s16(-limit_block-1)) == true);
+}