From a5a70f4b4d9f6226f18f6a33a905e1586623ef92 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Tue, 22 Nov 2022 14:07:58 +0100 Subject: [PATCH] LightTestUtil --- .../data/world/chunk/light/LightTestUtil.kt | 32 ++++++++ .../light/breaking/block/BlockLightBreakIT.kt | 73 ++++++++++--------- .../light/place/block/BlockLightPlaceIT.kt | 73 ++++++++++--------- 3 files changed, 106 insertions(+), 72 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/LightTestUtil.kt diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/LightTestUtil.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/LightTestUtil.kt new file mode 100644 index 000000000..7da58f5db --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/LightTestUtil.kt @@ -0,0 +1,32 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.data.world.chunk.light + +import de.bixilon.kotlinglm.vec3.Vec3i +import de.bixilon.minosoft.data.world.World +import de.bixilon.minosoft.data.world.chunk.Chunk +import org.testng.Assert + +object LightTestUtil { + + fun Chunk.assertLight(x: Int, y: Int, z: Int, expected: Int) { + val light = this.light[x, y, z] and 0xFF + Assert.assertEquals(light, expected) + } + + fun World.assertLight(x: Int, y: Int, z: Int, expected: Int) { + val light = this.getLight(Vec3i(x, y, z)) and 0xFF + Assert.assertEquals(light, expected) + } +} diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/breaking/block/BlockLightBreakIT.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/breaking/block/BlockLightBreakIT.kt index 3046c01bc..d08ce36e2 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/breaking/block/BlockLightBreakIT.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/breaking/block/BlockLightBreakIT.kt @@ -19,6 +19,7 @@ import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf import de.bixilon.minosoft.data.registries.blocks.StoneTestO import de.bixilon.minosoft.data.registries.blocks.TorchTest0 import de.bixilon.minosoft.data.world.WorldTestUtil.fill +import de.bixilon.minosoft.data.world.chunk.light.LightTestUtil.assertLight import de.bixilon.minosoft.modding.event.events.blocks.chunk.LightChangeEvent import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil @@ -33,134 +34,134 @@ class BlockLightBreakIT { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(8, 10, 8)), 0xF0) + world.assertLight(8, 10, 8, 0xF0) } fun nextToBlock1() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(8, 9, 8)), 0xF0) - assertEquals(world.getLight(Vec3i(8, 0, 8)), 0xF0) + world.assertLight(8, 9, 8, 0xF0) + world.assertLight(8, 0, 8, 0xF0) } fun nextToBlock2() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(8, 11, 8)), 0xF0) + world.assertLight(8, 11, 8, 0xF0) } fun nextToBlock3() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(7, 10, 8)), 0xF0) + world.assertLight(7, 10, 8, 0xF0) } fun nextToBlock4() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(9, 10, 8)), 0xF0) + world.assertLight(9, 10, 8, 0xF0) } fun nextToBlock5() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(8, 10, 7)), 0xF0) + world.assertLight(8, 10, 7, 0xF0) } fun nextToBlock6() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state world[Vec3i(8, 10, 8)] = null - assertEquals(world.getLight(Vec3i(8, 10, 9)), 0xF0) + world.assertLight(8, 10, 9, 0xF0) } fun nextNeighbour1() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = null - assertEquals(world.getLight(Vec3i(16, 17, 16)), 0xF0) + world.assertLight(16, 17, 16, 0xF0) } fun nextNeighbour2() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = null - assertEquals(world.getLight(Vec3i(17, 16, 16)), 0xF0) + world.assertLight(17, 16, 16, 0xF0) } fun nextNeighbour3() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(16, 16, 16)] = TorchTest0.state world[Vec3i(16, 16, 16)] = null - assertEquals(world.getLight(Vec3i(16, 16, 17)), 0xF0) + world.assertLight(16, 16, 17, 0xF0) } fun nextNeighbour4() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = null - assertEquals(world.getLight(Vec3i(17, 16, 17)), 0xF0) + world.assertLight(17, 16, 17, 0xF0) } fun nextNeighbour5() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = null - assertEquals(world.getLight(Vec3i(16, 17, 17)), 0xF0) + world.assertLight(16, 17, 17, 0xF0) } fun nextNeighbour6() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(17, 17, 17)] = TorchTest0.state world[Vec3i(17, 17, 17)] = null - assertEquals(world.getLight(Vec3i(17, 17, 16)), 0xF0) + world.assertLight(17, 17, 16, 0xF0) } fun totalPropagation1() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = null - assertEquals(world.getLight(Vec3i(12, 7, 12)), 0xF0) + world.assertLight(12, 7, 12, 0xF0) } fun totalPropagation2() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = null - assertEquals(world.getLight(Vec3i(12, 33, 12)), 0xF0) + world.assertLight(12, 33, 12, 0xF0) } fun totalPropagation3() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = null - assertEquals(world.getLight(Vec3i(-1, 33, 12)), 0xF0) + world.assertLight(-1, 33, 12, 0xF0) } fun totalPropagation4() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = null - assertEquals(world.getLight(Vec3i(25, 33, 12)), 0xF0) + world.assertLight(25, 33, 12, 0xF0) } fun totalPropagation5() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = null - assertEquals(world.getLight(Vec3i(12, 33, 25)), 0xF0) + world.assertLight(12, 33, 25, 0xF0) } fun totalPropagation6() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state world[Vec3i(12, 20, 12)] = null - assertEquals(world.getLight(Vec3i(12, 33, -1)), 0xF0) + world.assertLight(12, 33, -1, 0xF0) } fun lightUpdate() { @@ -191,8 +192,8 @@ class BlockLightBreakIT { world[Vec3i(8, 0, 8)] = TorchTest0.state world[Vec3i(8, 0, 8)] = null val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, -1, 8)], 0xF0) - assertEquals(chunk.light[Vec3i(9, -1, 8)], 0xF0) + chunk.assertLight(8, -1, 8, 0xF0) + chunk.assertLight(9, -1, 8, 0xF0) } @@ -201,8 +202,8 @@ class BlockLightBreakIT { world[Vec3i(8, 255, 8)] = TorchTest0.state world[Vec3i(8, 255, 8)] = null val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xF0) - assertEquals(chunk.light[Vec3i(9, 256, 8)], 0xF0) + chunk.assertLight(8, 256, 8, 0xF0) + chunk.assertLight(9, 256, 8, 0xF0) } fun bottomPropagation() { @@ -212,13 +213,13 @@ class BlockLightBreakIT { world[Vec3i(8, 0, 8)] = null val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, -1, 8)], 0x00) - assertEquals(chunk.light[Vec3i(9, -1, 8)], 0x00) + chunk.assertLight(8, -1, 8, 0x00) + chunk.assertLight(9, -1, 8, 0x00) - assertEquals(chunk.light[Vec3i(20, -1, 8)], 0x00) - assertEquals(chunk.light[Vec3i(8, -1, 8)], 0x00) - assertEquals(chunk.light[Vec3i(-4, -1, 20)], 0x00) - assertEquals(chunk.light[Vec3i(8, -1, -4)], 0x00) + chunk.assertLight(+20, -1, +8, 0x00) + chunk.assertLight(+8, -1, +8, 0x00) + chunk.assertLight(-4, -1, +20, 0x00) + chunk.assertLight(+8, -1, -4, 0x00) } fun topPropagation() { @@ -228,12 +229,12 @@ class BlockLightBreakIT { world[Vec3i(8, 255, 8)] = null val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xF0) - assertEquals(chunk.light[Vec3i(9, 256, 8)], 0xF0) + chunk.assertLight(8, 256, 8, 0xF0) + chunk.assertLight(9, 256, 8, 0xF0) - assertEquals(chunk.light[Vec3i(20, 256, 8)], 0xF0) - assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xF0) - assertEquals(chunk.light[Vec3i(-4, 256, 20)], 0xF0) - assertEquals(chunk.light[Vec3i(8, 256, -4)], 0xF0) + chunk.assertLight(+20, 256, +8, 0xF0) + chunk.assertLight(+8, 256, +8, 0xF0) + chunk.assertLight(-4, 256, +20, 0xF0) + chunk.assertLight(+8, 256, -4, 0xF0) } } diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/block/BlockLightPlaceIT.kt b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/block/BlockLightPlaceIT.kt index 65e033ebc..fe424dafd 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/block/BlockLightPlaceIT.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/data/world/chunk/light/place/block/BlockLightPlaceIT.kt @@ -19,6 +19,7 @@ import de.bixilon.kutil.collections.CollectionUtil.synchronizedSetOf import de.bixilon.minosoft.data.registries.blocks.StoneTestO import de.bixilon.minosoft.data.registries.blocks.TorchTest0 import de.bixilon.minosoft.data.world.WorldTestUtil.fill +import de.bixilon.minosoft.data.world.chunk.light.LightTestUtil.assertLight import de.bixilon.minosoft.modding.event.events.blocks.chunk.LightChangeEvent import de.bixilon.minosoft.modding.event.listener.CallbackEventListener.Companion.listen import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil @@ -32,116 +33,116 @@ class BlockLightPlaceIT { fun inBlock() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(8, 10, 8)), 0xFD) + world.assertLight(8, 10, 8, 0xFD) } fun nextToBlock1() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(8, 9, 8)), 0xFC) - assertEquals(world.getLight(Vec3i(8, 0, 8)), 0xF4) + world.assertLight(8, 9, 8, 0xFC) + world.assertLight(8, 0, 8, 0xF4) } fun nextToBlock2() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(8, 11, 8)), 0xFC) + world.assertLight(8, 11, 8, 0xFC) } fun nextToBlock3() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(7, 10, 8)), 0xFC) + world.assertLight(7, 10, 8, 0xFC) } fun nextToBlock4() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(9, 10, 8)), 0xFC) + world.assertLight(9, 10, 8, 0xFC) } fun nextToBlock5() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(8, 10, 7)), 0xFC) + world.assertLight(8, 10, 7, 0xFC) } fun nextToBlock6() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 10, 8)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(8, 10, 9)), 0xFC) + world.assertLight(8, 10, 9, 0xFC) } fun nextNeighbour1() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(16, 16, 16)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(16, 17, 16)), 0xFC) + world.assertLight(16, 17, 16, 0xFC) } fun nextNeighbour2() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(16, 16, 16)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(17, 16, 16)), 0xFC) + world.assertLight(17, 16, 16, 0xFC) } fun nextNeighbour3() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(16, 16, 16)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(16, 16, 17)), 0xFC) + world.assertLight(16, 16, 17, 0xFC) } fun nextNeighbour4() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(17, 17, 17)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(17, 16, 17)), 0xFC) + world.assertLight(17, 16, 17, 0xFC) } fun nextNeighbour5() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(17, 17, 17)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(16, 17, 17)), 0xFC) + world.assertLight(16, 17, 17, 0xFC) } fun nextNeighbour6() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(17, 17, 17)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(17, 17, 16)), 0xFC) + world.assertLight(17, 17, 16, 0xFC) } fun totalPropagation1() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(12, 7, 12)), 0xF1) + world.assertLight(12, 7, 12, 0xF1) } fun totalPropagation2() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(12, 33, 12)), 0xF1) + world.assertLight(12, 33, 12, 0xF1) } fun totalPropagation3() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(-1, 33, 12)), 0xF1) + world.assertLight(-1, 33, 12, 0xF1) } fun totalPropagation4() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(25, 33, 12)), 0xF1) + world.assertLight(25, 33, 12, 0xF1) } fun totalPropagation5() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(12, 33, 25)), 0xF1) + world.assertLight(12, 33, 25, 0xF1) } fun totalPropagation6() { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(12, 20, 12)] = TorchTest0.state - assertEquals(world.getLight(Vec3i(12, 33, -1)), 0xF1) + world.assertLight(12, 33, -1, 0xF1) } fun lightUpdate() { @@ -170,8 +171,8 @@ class BlockLightPlaceIT { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 0, 8)] = TorchTest0.state val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, -1, 8)], 0xFC) - assertEquals(chunk.light[Vec3i(9, -1, 8)], 0xFB) + chunk.assertLight(8, -1, 8, 0xFC) + chunk.assertLight(9, -1, 8, 0xFB) } @@ -179,8 +180,8 @@ class BlockLightPlaceIT { val world = ConnectionTestUtil.createConnection(3).world world[Vec3i(8, 255, 8)] = TorchTest0.state val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xFC) - assertEquals(chunk.light[Vec3i(9, 256, 8)], 0xFB) + chunk.assertLight(8, 256, 8, 0xFC) + chunk.assertLight(9, 256, 8, 0xFB) } fun bottomPropagation() { @@ -189,13 +190,13 @@ class BlockLightPlaceIT { world[Vec3i(8, 0, 8)] = TorchTest0.state val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, -1, 8)], 0x0C) - assertEquals(chunk.light[Vec3i(9, -1, 8)], 0x0B) + chunk.assertLight(8, -1, 8, 0x0C) + chunk.assertLight(9, -1, 8, 0x0B) - assertEquals(chunk.light[Vec3i(20, -1, 8)], 0x01) - assertEquals(chunk.light[Vec3i(8, -1, 8)], 0x01) - assertEquals(chunk.light[Vec3i(-4, -1, 20)], 0x01) - assertEquals(chunk.light[Vec3i(8, -1, -4)], 0x01) + chunk.assertLight(+20, -1, +8, 0x01) + chunk.assertLight(+8, -1, +8, 0x01) + chunk.assertLight(-4, -1, +20, 0x01) + chunk.assertLight(+8, -1, -4, 0x01) } fun topPropagation() { @@ -204,12 +205,12 @@ class BlockLightPlaceIT { world[Vec3i(8, 255, 8)] = TorchTest0.state val chunk = world[Vec2i(0, 0)]!! - assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xFC) - assertEquals(chunk.light[Vec3i(9, 256, 8)], 0xFB) + chunk.assertLight(8, 256, 8, 0xFC) + chunk.assertLight(9, 256, 8, 0xFB) - assertEquals(chunk.light[Vec3i(20, 256, 8)], 0xF1) - assertEquals(chunk.light[Vec3i(8, 256, 8)], 0xF1) - assertEquals(chunk.light[Vec3i(-4, 256, 20)], 0xF1) - assertEquals(chunk.light[Vec3i(8, 256, -4)], 0xF1) + chunk.assertLight(+20, 256, +8, 0xF1) + chunk.assertLight(+8, 256, +8, 0xF1) + chunk.assertLight(-4, 256, +20, 0xF1) + chunk.assertLight(+8, 256, -4, 0xF1) } }