aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_map.cpp
blob: 82e55e1aab75d7811d32a431c6be9d9ec31586ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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);
}