From 56888c63a159deaeffdb16785f7605dff835ee3a Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Sun, 30 Dec 2018 15:07:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D0=B8=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20?= =?UTF-8?q?RegionTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/mc/world/anvil/RegionTest.java | 172 ++++++++++-------- 1 file changed, 96 insertions(+), 76 deletions(-) diff --git a/anvil-loader/src/test/java/mc/world/anvil/RegionTest.java b/anvil-loader/src/test/java/mc/world/anvil/RegionTest.java index e8cc400..233c959 100644 --- a/anvil-loader/src/test/java/mc/world/anvil/RegionTest.java +++ b/anvil-loader/src/test/java/mc/world/anvil/RegionTest.java @@ -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 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); } }