diff --git a/src/main/java/net/minestom/server/instance/palette/PaletteImpl.java b/src/main/java/net/minestom/server/instance/palette/PaletteImpl.java index a7b2ba9e1..8964bc23e 100644 --- a/src/main/java/net/minestom/server/instance/palette/PaletteImpl.java +++ b/src/main/java/net/minestom/server/instance/palette/PaletteImpl.java @@ -258,8 +258,8 @@ final class PaletteImpl implements Palette, Cloneable { } private static int validateDimension(int dimension) { - if(dimension <= 0) { - throw new IllegalArgumentException("Dimension must be greater 0"); + if(dimension <= 1) { + throw new IllegalArgumentException("Dimension must be greater 1"); } double log2 = Math.log(dimension) / Math.log(2); diff --git a/src/test/java/net/minestom/server/instance/PaletteTest.java b/src/test/java/net/minestom/server/instance/PaletteTest.java index 49df96ff2..0917a522b 100644 --- a/src/test/java/net/minestom/server/instance/PaletteTest.java +++ b/src/test/java/net/minestom/server/instance/PaletteTest.java @@ -111,18 +111,46 @@ public class PaletteTest { @Test public void dimension() { + assertThrows(Exception.class, () -> Palette.newPalette(-4, 5, 3, 1)); assertThrows(Exception.class, () -> Palette.newPalette(0, 5, 3, 1)); assertThrows(Exception.class, () -> Palette.newPalette(1, 5, 3, 1)); assertDoesNotThrow(() -> Palette.newPalette(2, 5, 3, 1)); assertThrows(Exception.class, () -> Palette.newPalette(3, 5, 3, 1)); assertDoesNotThrow(() -> Palette.newPalette(4, 5, 3, 1)); + assertThrows(Exception.class, () -> Palette.newPalette(6, 5, 3, 1)); + assertDoesNotThrow(() -> Palette.newPalette(16, 5, 3, 1)); } private static List testPalettes() { List palettes = new ArrayList<>(); - for (int i = 4; i < 16; i += 2) { - palettes.add(Palette.newPalette(i, 5, 3, 1)); - } + palettes.add(Palette.newPalette(2, 5, 3, 1)); + palettes.add(Palette.newPalette(4, 5, 3, 1)); + palettes.add(Palette.newPalette(8, 5, 3, 1)); + palettes.add(Palette.newPalette(16, 5, 3, 1)); return palettes; } + + @Test + public void bulk() { + var palettes = testPalettes(); + for (Palette palette : palettes) { + final int dimension = palette.dimension(); + // Place + for (int x = 0; x < dimension; x++) { + for (int y = 0; y < dimension; y++) { + for (int z = 0; z < dimension; z++) { + palette.set(x, y, z, x + y + z); + } + } + } + // Verify + for (int x = 0; x < dimension; x++) { + for (int y = 0; y < dimension; y++) { + for (int z = 0; z < dimension; z++) { + assertEquals(x + y + z, palette.get(x, y, z)); + } + } + } + } + } }