Testing and fixing
This commit is contained in:
parent
f7cef3fdf8
commit
34e036c6f6
@ -24,5 +24,6 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
@ -6,6 +6,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@ -188,9 +189,10 @@ public class World {
|
||||
}
|
||||
|
||||
private static List<Integer> generateLinearSpawnpoints(int start, int length, int maxStep) {
|
||||
int stepCount = (int) Math.ceil((double) length / maxStep);
|
||||
double stepCount = Math.ceil((double) length / maxStep);
|
||||
if (stepCount == 0) return Arrays.asList(start);
|
||||
double realStep = length / stepCount;
|
||||
return IntStream.rangeClosed(0, stepCount).mapToObj(i -> start + (int) (realStep * i))
|
||||
return IntStream.rangeClosed(0, (int) stepCount).mapToObj(i -> start + (int) (realStep * i))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
50
src/test/java/SpawnpointTest.java
Normal file
50
src/test/java/SpawnpointTest.java
Normal file
@ -0,0 +1,50 @@
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joml.Vector2i;
|
||||
import org.junit.Test;
|
||||
|
||||
import morlok8k.MinecraftLandGenerator.World;
|
||||
|
||||
public class SpawnpointTest {
|
||||
|
||||
static {
|
||||
System.setProperty("joml.format", "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTest() {
|
||||
test(0, 0, 25, 25, 25);
|
||||
test(-100, 10, 500, 400, 25);
|
||||
test(-256, 16, 512, 256, 25);
|
||||
test(-255, 15, 512, 256, 25);
|
||||
test(-256, 16, 511, 255, 25);
|
||||
test(-255, 15, 511, 255, 25);
|
||||
test(25, 24, 50, 49, 25);
|
||||
test(25, 24, 49, 50, 25);
|
||||
}
|
||||
|
||||
private static void test(int startX, int startZ, int width, int height, int increment) {
|
||||
List<Vector2i> spawn = World.generateSpawnpoints(startX, startZ, width, height, increment);
|
||||
int margin = increment / 2;
|
||||
Set<Vector2i> coverage = new HashSet<>();
|
||||
for (Vector2i v : spawn) {
|
||||
for (int z = v.y - margin; z <= v.y + margin; z++)
|
||||
for (int x = v.x - margin; x <= v.x + margin; x++)
|
||||
coverage.add(new Vector2i(x, z));
|
||||
}
|
||||
for (int z = startZ; z < startZ + height; z++) {
|
||||
for (int x = startX; x < startX + width; x++) {
|
||||
assertTrue(
|
||||
"Chunk (" + x + ", " + z + ") in (" + startX + ", " + startZ + ", " + width
|
||||
+ ", " + height
|
||||
+ ") should be covered the spawn chunks, but they were " + spawn,
|
||||
coverage.remove(new Vector2i(x, z)));
|
||||
}
|
||||
}
|
||||
assertTrue(coverage.isEmpty());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user