summaryrefslogtreecommitdiff
path: root/src/emerge.cpp
diff options
context:
space:
mode:
authorparamat <mat.gregory@virginmedia.com>2015-08-03 04:34:11 +0100
committerparamat <mat.gregory@virginmedia.com>2015-08-03 06:39:23 +0100
commit7a6e4dc54a3eb4187e67a21c4ece60f39bb1d13b (patch)
tree26646570c7adbb988392bb15af1435257e65468a /src/emerge.cpp
parentcf77e0333d1ba0aa81fdce80cd0fa32f137b0a47 (diff)
downloadminetest-7a6e4dc54a3eb4187e67a21c4ece60f39bb1d13b.tar.gz
minetest-7a6e4dc54a3eb4187e67a21c4ece60f39bb1d13b.tar.bz2
minetest-7a6e4dc54a3eb4187e67a21c4ece60f39bb1d13b.zip
Cavegen V6: Make all caves consistent with 0.4.12 stable
When tunnels entirely above ground were avoided, the missing pseudorandom calls changed the allowed caves. Now, above ground tunnels are not placed while still running all previous pseudorandom calls.
Diffstat (limited to 'src/emerge.cpp')
0 files changed, 0 insertions, 0 deletions
17'>117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
 /*
Minetest
Copyright (C) 2010-2014 kwolekr, Ryan Kwolek <kwolekr@minetest.net>

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 "util/numeric.h"
#include "exceptions.h"
#include "noise.h"

class TestRandom : public TestBase {
public:
	TestRandom() { TestManager::registerTestModule(this); }
	const char *getName() { return "TestRandom"; }

	void runTests(IGameDef *gamedef);

	void testPseudoRandom();
	void testPseudoRandomRange();
	void testPcgRandom();
	void testPcgRandomRange();
	void testPcgRandomBytes();
	void testPcgRandomNormalDist();

	static const int expected_pseudorandom_results[256];
	static const u32 expected_pcgrandom_results[256];
	static const u8 expected_pcgrandom_bytes_result[24];
	static const u8 expected_pcgrandom_bytes_result2[24];
};

static TestRandom g_test_instance;

void TestRandom::runTests(IGameDef *gamedef)
{
	TEST(testPseudoRandom);
	TEST(testPseudoRandomRange);
	TEST(testPcgRandom);
	TEST(testPcgRandomRange);
	TEST(testPcgRandomBytes);
	TEST(testPcgRandomNormalDist);
}

////////////////////////////////////////////////////////////////////////////////

void TestRandom::testPseudoRandom()
{
	PseudoRandom pr(814538);

	for (u32 i = 0; i != 256; i++)
		UASSERTEQ(int, pr.next(), expected_pseudorandom_results[i]);
}


void TestRandom::testPseudoRandomRange()
{
	PseudoRandom pr((int)time(NULL));

	EXCEPTION_CHECK(PrngException, pr.range(2000, 6000));
	EXCEPTION_CHECK(PrngException, pr.range(5, 1));

	for (u32 i = 0; i != 32768; i++) {
		int min = (pr.next() % 3000) - 500;
		int max = (pr.next() % 3000) - 500;
		if (min > max)
			SWAP(int, min, max);

		int randval = pr.range(min, max);
		UASSERT(randval >= min);
		UASSERT(randval <= max);
	}
}


void TestRandom::testPcgRandom()
{
	PcgRandom pr(814538, 998877);

	for (u32 i = 0; i != 256; i++)
		UASSERTEQ(u32, pr.next(), expected_pcgrandom_results[i]);
}


void TestRandom::testPcgRandomRange()
{
	PcgRandom pr((int)time(NULL));

	EXCEPTION_CHECK(PrngException, pr.range(5, 1));

	// Regression test for bug 3027
	pr.range(pr.RANDOM_MIN, pr.RANDOM_MAX);