Archived
0

метод теста поделен на мелкие методы

This commit is contained in:
2018-12-23 12:02:11 +03:00
parent 6f490ff946
commit 26368a5616

View File

@@ -1,6 +1,7 @@
package mc.core.network.proto_1_12_2.packets; package mc.core.network.proto_1_12_2.packets;
import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream; import mc.core.network.proto_1_12_2.ByteArrayOutputNetStream;
import mc.core.network.proto_1_12_2.packets.DumbChunkData.DumbChunkSection;
import mc.core.world.Biome; import mc.core.world.Biome;
import mc.core.world.block.BlockFactory; import mc.core.world.block.BlockFactory;
import mc.core.world.block.BlockType; import mc.core.world.block.BlockType;
@@ -124,44 +125,57 @@ class ChunkDataPacketTest {
assertEquals(expectedDumbChunkData.getData().length, actualDumbChunkData.getData().length); assertEquals(expectedDumbChunkData.getData().length, actualDumbChunkData.getData().length);
for (int numberSection = 0; numberSection < expectedDumbChunkData.getData().length; numberSection++) { for (int numberSection = 0; numberSection < expectedDumbChunkData.getData().length; numberSection++) {
final DumbChunkData.DumbChunkSection expectedDumbChunkSection = expectedDumbChunkData.getData()[numberSection]; final DumbChunkSection expectedDumbChunkSection = expectedDumbChunkData.getData()[numberSection];
final DumbChunkData.DumbChunkSection actualDumbChunkSection = actualDumbChunkData.getData()[numberSection]; final DumbChunkSection actualDumbChunkSection = actualDumbChunkData.getData()[numberSection];
// Palette // Palette
assertEquals(expectedDumbChunkSection.getBitsPerBlock(), actualDumbChunkSection.getBitsPerBlock()); testPalette(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
if (expectedDumbChunkSection.getPalette().size() > actualDumbChunkSection.getPalette().size()) {
for (int j = 0; j < actualDumbChunkSection.getPalette().size(); j++) {
assertTrue(expectedDumbChunkSection.getPalette().contains(
actualDumbChunkSection.getPalette().get(j)
), String.format("[%d] Palette not contains %s", numberSection, actualDumbChunkSection.getPalette().get(j)));
}
} else {
for (int j = 0; j < expectedDumbChunkSection.getPalette().size(); j++) {
assertTrue(actualDumbChunkSection.getPalette().contains(
expectedDumbChunkSection.getPalette().get(j)
), String.format("[%d] Palette not contains %s", numberSection, actualDumbChunkSection.getPalette().get(j)));
}
}
// Data // Data
assertEquals(expectedDumbChunkSection.getData().size(), actualDumbChunkSection.getData().size()); testDataBlock(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
for (int j = 0; j < expectedDumbChunkSection.getData().size(); j++) { // Block and Sky light
testLight(expectedDumbChunkSection, actualDumbChunkSection, numberSection);
}
}
private void testPalette(DumbChunkSection expected, DumbChunkSection actual, int numberSection) {
assertEquals(expected.getBitsPerBlock(), actual.getBitsPerBlock());
if (expected.getPalette().size() > actual.getPalette().size()) {
for (int j = 0; j < actual.getPalette().size(); j++) {
assertTrue(expected.getPalette().contains(
actual.getPalette().get(j)
), String.format("[%d] Palette not contains %s", numberSection, actual.getPalette().get(j)));
}
} else {
for (int j = 0; j < expected.getPalette().size(); j++) {
assertTrue(actual.getPalette().contains(
expected.getPalette().get(j)
), String.format("[%d] Palette not contains %s", numberSection, actual.getPalette().get(j)));
}
}
}
private void testDataBlock(DumbChunkSection expected, DumbChunkSection actual, int numberSection) {
assertEquals(expected.getData().size(), actual.getData().size());
for (int j = 0; j < expected.getData().size(); j++) {
assertEquals( assertEquals(
expectedDumbChunkSection.getData().get(j), expected.getData().get(j),
actualDumbChunkSection.getData().get(j), actual.getData().get(j),
String.format("[%d] Data (blocks)", numberSection) String.format("[%d] Data (blocks)", numberSection)
); );
} }
}
private void testLight(DumbChunkSection expected, DumbChunkSection actual, int numberSection) {
// Block light // Block light
assertArrayEquals(expectedDumbChunkSection.getBlockLight(), actualDumbChunkSection.getBlockLight(), assertArrayEquals(expected.getBlockLight(), actual.getBlockLight(),
String.format("[%d] Block light", numberSection)); String.format("[%d] Block light", numberSection));
// Sky light // Sky light
assertArrayEquals(expectedDumbChunkSection.getSkyLight(), actualDumbChunkSection.getSkyLight(), assertArrayEquals(expected.getSkyLight(), actual.getSkyLight(),
String.format("[%d] Sky light", numberSection)); String.format("[%d] Sky light", numberSection));
} }
}
} }