Archived
0

параметеризирован RegionTest

This commit is contained in:
2018-12-30 15:07:25 +03:00
parent 7c9764f763
commit 56888c63a1

View File

@@ -10,9 +10,12 @@ import mc.core.world.block.BlockType;
import mc.core.world.chunk.Chunk;
import mc.core.world.chunk.ChunkSection;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.nio.file.Paths;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -26,85 +29,102 @@ class RegionTest {
region = new Region(Paths.get(RegionTest.class.getResource("/region/r.0.0.mca").toURI()).toFile());
}
@Test
void getChunkSection() {
final Chunk chunk = region.getChunk(0, 0);
assertNotNull(chunk);
private static Stream<Arguments> streamArguments() {
ChunkChecker chunkChecker00 = new ChunkChecker() {
private void checkSection0(ChunkSection chunkSection) {
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
Block block = chunkSection.getBlock(x, y, z);
String msg = String.format("coords: %d %d %d", x, y, z);
ChunkSection chunkSection = chunk.getChunkSection(0);
assertNotNull(chunkSection);
checkSection1(chunkSection);
chunkSection = chunk.getChunkSection(1);
assertNotNull(chunkSection);
checkSection2(chunkSection);
}
private void checkSection1(ChunkSection chunkSection) {
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
Block block = chunkSection.getBlock(x, y, z);
String msg = String.format("coords: %d %d %d", x, y, z);
if (y == 0) {
// @formatter:off
if (x == 0 && z == 0) assertEquals(BlockType.STONE, block.getType(), msg);
else if (x == 15 && z == 0) assertEquals(BlockType.GRANITE, block.getType(), msg);
else if (x == 0 && z == 15) assertEquals(BlockType.POLISHED_GRANITE, block.getType(), msg);
else if (x == 15 && z == 15) assertEquals(BlockType.DIORITE, block.getType(), msg);
else assertEquals(BlockType.BEDROCK, block.getType(), msg);
// @formatter:on
} else {
assertEquals(BlockType.STONE, block.getType(), msg);
}
}
}
}
}
private CompoundTag createExceptedNBT(Block block) {
CompoundMap compoundMap = new CompoundMap();
compoundMap.put(new IntTag("x", block.getLocation().getX()));
compoundMap.put(new IntTag("y", block.getLocation().getY()));
compoundMap.put(new IntTag("z", block.getLocation().getZ()));
compoundMap.put(new StringTag("id", block.getType().getNamedId()));
return new CompoundTag("", compoundMap);
}
private void checkSection2(ChunkSection chunkSection) {
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
Block block = chunkSection.getBlock(x, y, z);
String msg = String.format("coords: %d %d %d", x, y, z);
// @formatter:off
if (y == 0) assertEquals(BlockType.DIRT, block.getType(), msg);
else if (y == 1) assertEquals(BlockType.GRASS, block.getType(), msg);
else if (y == 2) {
if ((x == 2 || x == 4 || x == 5) && z == 1) {
assertEquals(BlockType.CHEST_NORTH, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else if ((x == 2 || x == 3 || x == 5) && z == 6) {
assertEquals(BlockType.CHEST_SOUTH, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else if (x == 1 && (z == 2 || z == 3 || z == 5)) {
assertEquals(BlockType.CHEST_WEST, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else if (x == 6 && (z == 2 || z == 4 || z == 5)) {
assertEquals(BlockType.CHEST_EAST, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else {
assertEquals(BlockType.AIR, block.getType(), msg);
if (y == 0) {
// @formatter:off
if (x == 0 && z == 0) assertEquals(BlockType.STONE, block.getType(), msg);
else if (x == 15 && z == 0) assertEquals(BlockType.GRANITE, block.getType(), msg);
else if (x == 0 && z == 15) assertEquals(BlockType.POLISHED_GRANITE, block.getType(), msg);
else if (x == 15 && z == 15) assertEquals(BlockType.DIORITE, block.getType(), msg);
else assertEquals(BlockType.BEDROCK, block.getType(), msg);
// @formatter:on
} else {
assertEquals(BlockType.STONE, block.getType(), msg);
}
}
}
else assertEquals(BlockType.AIR, block.getType(), msg);
// @formatter:on
}
}
}
private CompoundTag createExceptedNBT(Block block) {
CompoundMap compoundMap = new CompoundMap();
compoundMap.put(new IntTag("x", block.getLocation().getX()));
compoundMap.put(new IntTag("y", block.getLocation().getY()));
compoundMap.put(new IntTag("z", block.getLocation().getZ()));
compoundMap.put(new StringTag("id", block.getType().getNamedId()));
return new CompoundTag("", compoundMap);
}
private void checkSection1(ChunkSection chunkSection) {
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
Block block = chunkSection.getBlock(x, y, z);
String msg = String.format("coords: %d %d %d", x, y, z);
// @formatter:off
if (y == 0) assertEquals(BlockType.DIRT, block.getType(), msg);
else if (y == 1) assertEquals(BlockType.GRASS, block.getType(), msg);
else if (y == 2) {
if ((x == 2 || x == 4 || x == 5) && z == 1) {
assertEquals(BlockType.CHEST_NORTH, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else if ((x == 2 || x == 3 || x == 5) && z == 6) {
assertEquals(BlockType.CHEST_SOUTH, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else if (x == 1 && (z == 2 || z == 3 || z == 5)) {
assertEquals(BlockType.CHEST_WEST, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else if (x == 6 && (z == 2 || z == 4 || z == 5)) {
assertEquals(BlockType.CHEST_EAST, block.getType(), msg);
assertEquals(createExceptedNBT(block), block.getNBTData());
} else {
assertEquals(BlockType.AIR, block.getType(), msg);
}
}
else assertEquals(BlockType.AIR, block.getType(), msg);
// @formatter:on
}
}
}
}
@Override
public void check(Chunk chunk) {
ChunkSection chunkSection = chunk.getChunkSection(0);
assertNotNull(chunkSection);
checkSection0(chunkSection);
chunkSection = chunk.getChunkSection(1);
assertNotNull(chunkSection);
checkSection1(chunkSection);
}
};
return Stream.of(
Arguments.of(0, 0, chunkChecker00)
);
}
@ParameterizedTest
@MethodSource("streamArguments")
void getChunkSection(int chunkX, int chunkZ, ChunkChecker chunkChecker) {
final Chunk chunk = region.getChunk(chunkX, chunkZ);
assertNotNull(chunk);
chunkChecker.check(chunk);
}
interface ChunkChecker {
void check(Chunk chunk);
}
}