test_map.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Minetest
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as published by
  5. the Free Software Foundation; either version 2.1 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  14. */
  15. #include "test.h"
  16. #include <cstdio>
  17. #include "mapblock.h"
  18. class TestMap : public TestBase
  19. {
  20. public:
  21. TestMap() { TestManager::registerTestModule(this); }
  22. const char *getName() { return "TestMap"; }
  23. void runTests(IGameDef *gamedef);
  24. void testMaxMapgenLimit();
  25. };
  26. static TestMap g_test_instance;
  27. void TestMap::runTests(IGameDef *gamedef)
  28. {
  29. TEST(testMaxMapgenLimit);
  30. }
  31. ////////////////////////////////////////////////////////////////////////////////
  32. void TestMap::testMaxMapgenLimit()
  33. {
  34. // limit must end on a mapblock boundary
  35. UASSERTEQ(int, MAX_MAP_GENERATION_LIMIT % MAP_BLOCKSIZE, MAP_BLOCKSIZE - 1);
  36. // objectpos_over_limit should do exactly this except the last node
  37. // actually spans from LIMIT-0.5 to LIMIT+0.5
  38. float limit_times_bs = MAX_MAP_GENERATION_LIMIT * BS;
  39. UASSERT(objectpos_over_limit(v3f(limit_times_bs-BS/2)) == false);
  40. UASSERT(objectpos_over_limit(v3f(limit_times_bs)) == false);
  41. UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS/2)) == false);
  42. UASSERT(objectpos_over_limit(v3f(limit_times_bs+BS)) == true);
  43. UASSERT(objectpos_over_limit(v3f(-limit_times_bs+BS/2)) == false);
  44. UASSERT(objectpos_over_limit(v3f(-limit_times_bs)) == false);
  45. UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS/2)) == false);
  46. UASSERT(objectpos_over_limit(v3f(-limit_times_bs-BS)) == true);
  47. // blockpos_over_max_limit
  48. s16 limit_block = MAX_MAP_GENERATION_LIMIT / MAP_BLOCKSIZE;
  49. UASSERT(blockpos_over_max_limit(v3s16(limit_block)) == false);
  50. UASSERT(blockpos_over_max_limit(v3s16(limit_block+1)) == true);
  51. UASSERT(blockpos_over_max_limit(v3s16(-limit_block)) == false);
  52. UASSERT(blockpos_over_max_limit(v3s16(-limit_block-1)) == true);
  53. }