From 9327dfaccfa28b89574c8feab018e5548bccd1d5 Mon Sep 17 00:00:00 2001 From: Eoghanmc22 Date: Mon, 3 Jan 2022 21:16:22 -0500 Subject: [PATCH] Fix Palette test --- .../server/instance/palette/PaletteImpl.java | 4 +-- .../minestom/server/instance/PaletteTest.java | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) 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)); + } + } + } + } + } }