Fixed tests environments.

Added basic islandworldmapper to test for block value consistency.

UniBiomeGenerator tests now produce new random object with same seed.
This commit is contained in:
Harrison Deng 2020-04-29 19:40:02 -05:00
parent c6fd9a833c
commit c63298bcaa
2 changed files with 66 additions and 3 deletions

View File

@ -0,0 +1,63 @@
package ca.recrown.islandsurvivalcraft.world;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Random;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import ca.recrown.islandsurvivalcraft.caching.Cache;
import ca.recrown.islandsurvivalcraft.datatypes.Point2;
@TestInstance(Lifecycle.PER_CLASS)
public class IslandWorldMapperTest {
public final Cache<Point2, Double> blockValCache = new Cache<>(2048);
public final int SEED = 102385923;
public Random random = new Random(SEED);
public IslandWorldMapper mapper = new IslandWorldMapper(random, blockValCache);
public final double[][] answers = new double[2048][2048];
@BeforeAll
public void setUp() {
for (int x = 0; x < answers.length; x++) {
for (int y = 0; y < answers[x].length; y++) {
answers[x][y] = mapper.getWorldBlockValue(x, y);
}
}
blockValCache.clearCache();
}
@AfterEach
public void individualCleanup() {
blockValCache.clearCache();
}
@BeforeEach
public void individualSetUp() {
random = new Random(SEED);
mapper = new IslandWorldMapper(random, blockValCache);
}
@Test
public void testBlockValueConsistency() {
for (int x = 0; x < answers.length; x++) {
for (int y = 0; y < answers[x].length; y++) {
assertEquals(answers[x][y], mapper.getWorldBlockValue(x, y), String.format("Occurred at (%d, %d)", x, y));
}
}
}
@Test
public void testBlockValueConsistencyRandom() {
for (int amount = 0; amount < 1024; amount++) {
int x = random.nextInt(answers.length);
int y = random.nextInt(answers[x].length);
assertEquals(answers[x][y], mapper.getWorldBlockValue(x, y), String.format("Occurred at (%d, %d)", x, y));
}
}
}

View File

@ -25,10 +25,9 @@ import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper;
public class UniBiomeIslandGeneratorTest {
private final int SEED = 249398015;
private final DummyWorld dummyWorld = new DummyWorld();
private final Cache<Point2, Double> blockValueCache = new Cache<>(102400);
private final Cache<Point2, Biome[]> biomeCache = new Cache<>(102400);
private final Cache<Point2, Double> blockValueCache = new Cache<>(4096);
private final Cache<Point2, Biome[]> biomeCache = new Cache<>(4096);
private final Cache<Point2, Boolean> chunkExistenceCache = new Cache<>(16384);
private final Random rand = new Random(SEED);
private class BiomeGenTask implements Runnable {
private final int amount;
@ -48,6 +47,7 @@ public class UniBiomeIslandGeneratorTest {
}
public void generateBiome(int chunkX, int chunkZ) {
Random rand = new Random(SEED);
IslandWorldMapper mapper = new IslandWorldMapper(rand, blockValueCache);
TemperatureMapGenerator temperatureMapGenerator = new TemperatureMapGenerator(SEED);
BiomeSelector biomeSelector = new BiomeSelector();