From e5720b4505cdb05db1235bca14c0e74fead8dee1 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 29 Aug 2021 19:14:08 -0700 Subject: [PATCH 1/4] bugfix: add cleanup to clear blocks --- src/test/java/org/terasology/TextWorldBuilder.java | 14 ++++++++++++++ .../navgraph/ConnectNavGraphChunkTest.java | 7 +++++++ .../org/terasology/navgraph/ContourFinderTest.java | 7 +++++++ .../org/terasology/navgraph/FloorFinderTest.java | 6 ++++++ .../org/terasology/navgraph/RegionFinderTest.java | 6 ++++++ .../navgraph/WalkableBlockFinderTest.java | 6 ++++++ .../org/terasology/pathfinding/HAStarLoSTest.java | 6 ++++++ .../org/terasology/pathfinding/HAStarTest.java | 6 ++++++ .../org/terasology/pathfinding/PathfinderTest.java | 6 ++++++ 9 files changed, 64 insertions(+) diff --git a/src/test/java/org/terasology/TextWorldBuilder.java b/src/test/java/org/terasology/TextWorldBuilder.java index 4418e12..82ff2a5 100644 --- a/src/test/java/org/terasology/TextWorldBuilder.java +++ b/src/test/java/org/terasology/TextWorldBuilder.java @@ -3,18 +3,23 @@ package org.terasology; import org.joml.Vector3i; +import org.joml.Vector3ic; import org.terasology.engine.context.Context; import org.terasology.engine.world.WorldProvider; import org.terasology.engine.world.block.Block; +import org.terasology.engine.world.block.BlockArea; import org.terasology.engine.world.block.BlockManager; +import org.terasology.engine.world.block.BlockRegion; import org.terasology.engine.world.block.family.SymmetricFamily; import org.terasology.engine.world.block.loader.BlockFamilyDefinition; import org.terasology.engine.world.block.loader.BlockFamilyDefinitionData; import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.gestalt.assets.management.AssetManager; +import org.terasology.joml.geom.Rectanglei; import java.util.ArrayList; import java.util.List; +import java.util.function.Consumer; /** * Created by synopia on 11.02.14. @@ -26,6 +31,7 @@ public class TextWorldBuilder { private WorldProvider world; private Block ground; private Block air; + private BlockRegion resetArea = new BlockRegion(BlockRegion.INVALID); public TextWorldBuilder(Context context) { world = context.get(WorldProvider.class); @@ -40,7 +46,15 @@ public TextWorldBuilder(Context context) { this.air = blockManager.getBlock(BlockManager.AIR_ID); } + public void reset() { + if(resetArea.isValid()) { + resetArea.forEach(pos -> setAir(pos.x(), pos.y(), pos.z())); + resetArea.set(BlockRegion.INVALID); + } + } + public void setGround(int x, int y, int z) { + resetArea.union(x, y, z); world.setBlock(new Vector3i(x, y, z), ground); } diff --git a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java index 7c19260..af22dd5 100644 --- a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java +++ b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -137,6 +138,12 @@ public void setup(Context context, WorldProvider worldProvider, ModuleTestingHel mteHelp.forceAndWaitForGeneration(chunkLocation); } + + @AfterEach + public void reset(){ + builder.reset(); + } + private void assertCenter(final NavGraphChunk center, NavGraphChunk left, NavGraphChunk up, NavGraphChunk right, NavGraphChunk down, String[] contours) { final Floor centerFloor = center.getFloor(0); Floor upFloor = up.getFloor(0); diff --git a/src/test/java/org/terasology/navgraph/ContourFinderTest.java b/src/test/java/org/terasology/navgraph/ContourFinderTest.java index 388e34e..1dbad4f 100644 --- a/src/test/java/org/terasology/navgraph/ContourFinderTest.java +++ b/src/test/java/org/terasology/navgraph/ContourFinderTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -421,6 +422,12 @@ public void setup(Context context, WorldProvider worldProvider, ModuleTestingHel mteHelp.forceAndWaitForGeneration(chunkLocation); } + + @AfterEach + public void reset(){ + builder.reset(); + } + private void assertContour(String[] ground, String[] contour) { builder.setGround(ground); final NavGraphChunk chunk = new NavGraphChunk(worldProvider, chunkLocation); diff --git a/src/test/java/org/terasology/navgraph/FloorFinderTest.java b/src/test/java/org/terasology/navgraph/FloorFinderTest.java index d28c8b0..4fad168 100644 --- a/src/test/java/org/terasology/navgraph/FloorFinderTest.java +++ b/src/test/java/org/terasology/navgraph/FloorFinderTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -308,6 +309,11 @@ public void setup(Context context, WorldProvider worldProvider, ModuleTestingHel mteHelp.forceAndWaitForGeneration(chunkLocation); } + @AfterEach + public void reset(){ + builder.reset(); + } + private void assertFloors(String[] data, String[] floors) { assertFloors(data, floors, null); } diff --git a/src/test/java/org/terasology/navgraph/RegionFinderTest.java b/src/test/java/org/terasology/navgraph/RegionFinderTest.java index bb13e01..6b4a329 100644 --- a/src/test/java/org/terasology/navgraph/RegionFinderTest.java +++ b/src/test/java/org/terasology/navgraph/RegionFinderTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -155,6 +156,11 @@ public void setup(Context context, WorldProvider worldProvider, ModuleTestingHel mteHelp.forceAndWaitForGeneration(chunkLocation); } + @AfterEach + public void reset(){ + builder.reset(); + } + private void assertRegions(String[] data, String[] regions) { assertRegions(data, regions, null); } diff --git a/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java b/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java index a3fa76e..8fb83ae 100644 --- a/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java +++ b/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; @@ -234,4 +235,9 @@ public void setup(Context context, WorldProvider worldProvider, ModuleTestingHel this.worldProvider = worldProvider; mteHelp.forceAndWaitForGeneration(chunkLocation); } + + @AfterEach + public void reset(){ + builder.reset(); + } } diff --git a/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java b/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java index bffa28f..33f72fa 100644 --- a/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java +++ b/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -143,6 +144,11 @@ public void setup(Context context, WorldProvider worldProvider, ModuleTestingHel mteHelp.forceAndWaitForGeneration(chunkLocation); } + @AfterEach + public void reset(){ + builder.reset(); + } + private void executeExample(String[] ground, String[] pathData) { builder.setGround(ground); final NavGraphChunk chunk = new NavGraphChunk(worldProvider, chunkLocation); diff --git a/src/test/java/org/terasology/pathfinding/HAStarTest.java b/src/test/java/org/terasology/pathfinding/HAStarTest.java index 92e8056..39b1dc5 100644 --- a/src/test/java/org/terasology/pathfinding/HAStarTest.java +++ b/src/test/java/org/terasology/pathfinding/HAStarTest.java @@ -4,6 +4,7 @@ import org.joml.Vector3i; import org.joml.Vector3ic; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -45,6 +46,11 @@ public void newWorldBuilder(Context context, WorldProvider worldProvider, Module chunk = new NavGraphChunk(worldProvider, chunkLocation); mteHelp.forceAndWaitForGeneration(chunkLocation); } + + @AfterEach + public void reset(){ + builder.reset(); + } @Test public void stairs2() { diff --git a/src/test/java/org/terasology/pathfinding/PathfinderTest.java b/src/test/java/org/terasology/pathfinding/PathfinderTest.java index 74bc314..fc46256 100644 --- a/src/test/java/org/terasology/pathfinding/PathfinderTest.java +++ b/src/test/java/org/terasology/pathfinding/PathfinderTest.java @@ -3,6 +3,7 @@ package org.terasology.pathfinding; import org.joml.Vector3i; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; @@ -42,6 +43,11 @@ public void setup(Context context) { pathfinder = new Pathfinder(world, null); } + @AfterEach + public void reset(){ + builder.reset(); + } + @Test public void test() { world.updateChunk(new Vector3i(0, 0, 0)); From fba4ac4aa3abb04c90771b1c6af9c84028dcc763 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 29 Aug 2021 20:17:02 -0700 Subject: [PATCH 2/4] chore:ConnectNavGraphChunkTest --- .../org/terasology/navgraph/ConnectNavGraphChunkTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java index af22dd5..3ccf4be 100644 --- a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java +++ b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java @@ -26,9 +26,9 @@ /** * @author synopia */ -@Tag("MteTest") -@ExtendWith(MTEExtension.class) -@Dependencies("Pathfinding") +//@Tag("MteTest") +//@ExtendWith(MTEExtension.class) +//@Dependencies("Pathfinding") public class ConnectNavGraphChunkTest { TextWorldBuilder builder; WorldProvider world; From d3a31125d2e0a7557d9f9a47ba14bcc037c757c2 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 29 Aug 2021 20:35:12 -0700 Subject: [PATCH 3/4] chore: modify force evaluation --- src/test/java/org/terasology/TextWorldBuilder.java | 7 ++++++- .../org/terasology/navgraph/ConnectNavGraphChunkTest.java | 3 +-- .../java/org/terasology/navgraph/ContourFinderTest.java | 3 +-- src/test/java/org/terasology/navgraph/FloorFinderTest.java | 3 +-- .../java/org/terasology/navgraph/RegionFinderTest.java | 3 +-- .../org/terasology/navgraph/WalkableBlockFinderTest.java | 3 +-- .../java/org/terasology/pathfinding/HAStarLoSTest.java | 3 +-- src/test/java/org/terasology/pathfinding/HAStarTest.java | 5 ++--- .../java/org/terasology/pathfinding/PathfinderTest.java | 5 +++-- 9 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/test/java/org/terasology/TextWorldBuilder.java b/src/test/java/org/terasology/TextWorldBuilder.java index 82ff2a5..d8cd4ce 100644 --- a/src/test/java/org/terasology/TextWorldBuilder.java +++ b/src/test/java/org/terasology/TextWorldBuilder.java @@ -16,6 +16,7 @@ import org.terasology.gestalt.assets.ResourceUrn; import org.terasology.gestalt.assets.management.AssetManager; import org.terasology.joml.geom.Rectanglei; +import org.terasology.moduletestingenvironment.ModuleTestingHelper; import java.util.ArrayList; import java.util.List; @@ -32,11 +33,13 @@ public class TextWorldBuilder { private Block ground; private Block air; private BlockRegion resetArea = new BlockRegion(BlockRegion.INVALID); + private ModuleTestingHelper helper; - public TextWorldBuilder(Context context) { + public TextWorldBuilder(Context context, ModuleTestingHelper helper) { world = context.get(WorldProvider.class); BlockManager blockManager = context.get(BlockManager.class); AssetManager assetManager = context.get(AssetManager.class); + this.helper = helper; BlockFamilyDefinitionData data = new BlockFamilyDefinitionData(); data.setBlockFamily(SymmetricFamily.class); @@ -56,10 +59,12 @@ public void reset() { public void setGround(int x, int y, int z) { resetArea.union(x, y, z); world.setBlock(new Vector3i(x, y, z), ground); + this.helper.forceAndWaitForGeneration(new Vector3i(x, y, z)); } public void setAir(int x, int y, int z) { world.setBlock(new Vector3i(x, y, z), air); + this.helper.forceAndWaitForGeneration(new Vector3i(x, y, z)); } public void setGround(String... lines) { diff --git a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java index 3ccf4be..3649ecf 100644 --- a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java +++ b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java @@ -133,9 +133,8 @@ public void test2() { @BeforeEach public void setup(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); world = worldProvider; - mteHelp.forceAndWaitForGeneration(chunkLocation); } diff --git a/src/test/java/org/terasology/navgraph/ContourFinderTest.java b/src/test/java/org/terasology/navgraph/ContourFinderTest.java index 1dbad4f..2452170 100644 --- a/src/test/java/org/terasology/navgraph/ContourFinderTest.java +++ b/src/test/java/org/terasology/navgraph/ContourFinderTest.java @@ -417,9 +417,8 @@ public void testRectangle() { @BeforeEach public void setup(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); this.worldProvider = worldProvider; - mteHelp.forceAndWaitForGeneration(chunkLocation); } diff --git a/src/test/java/org/terasology/navgraph/FloorFinderTest.java b/src/test/java/org/terasology/navgraph/FloorFinderTest.java index 4fad168..a95084b 100644 --- a/src/test/java/org/terasology/navgraph/FloorFinderTest.java +++ b/src/test/java/org/terasology/navgraph/FloorFinderTest.java @@ -304,9 +304,8 @@ public void testSingleFloor() { @BeforeEach public void setup(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); this.worldProvider = worldProvider; - mteHelp.forceAndWaitForGeneration(chunkLocation); } @AfterEach diff --git a/src/test/java/org/terasology/navgraph/RegionFinderTest.java b/src/test/java/org/terasology/navgraph/RegionFinderTest.java index 6b4a329..5ff1c0a 100644 --- a/src/test/java/org/terasology/navgraph/RegionFinderTest.java +++ b/src/test/java/org/terasology/navgraph/RegionFinderTest.java @@ -151,9 +151,8 @@ public void bigTest() { @BeforeEach public void setup(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); this.worldProvider = worldProvider; - mteHelp.forceAndWaitForGeneration(chunkLocation); } @AfterEach diff --git a/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java b/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java index 8fb83ae..e330cf9 100644 --- a/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java +++ b/src/test/java/org/terasology/navgraph/WalkableBlockFinderTest.java @@ -231,9 +231,8 @@ public char run(int x, int y, int z, char value) { @BeforeEach public void setup(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); this.worldProvider = worldProvider; - mteHelp.forceAndWaitForGeneration(chunkLocation); } @AfterEach diff --git a/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java b/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java index 33f72fa..cb8431d 100644 --- a/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java +++ b/src/test/java/org/terasology/pathfinding/HAStarLoSTest.java @@ -139,9 +139,8 @@ public void simple() { @BeforeEach public void setup(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); this.worldProvider = worldProvider; - mteHelp.forceAndWaitForGeneration(chunkLocation); } @AfterEach diff --git a/src/test/java/org/terasology/pathfinding/HAStarTest.java b/src/test/java/org/terasology/pathfinding/HAStarTest.java index 39b1dc5..5178c70 100644 --- a/src/test/java/org/terasology/pathfinding/HAStarTest.java +++ b/src/test/java/org/terasology/pathfinding/HAStarTest.java @@ -42,11 +42,10 @@ public class HAStarTest { @BeforeEach public void newWorldBuilder(Context context, WorldProvider worldProvider, ModuleTestingHelper mteHelp) { - builder = new TextWorldBuilder(context); + builder = new TextWorldBuilder(context, mteHelp); chunk = new NavGraphChunk(worldProvider, chunkLocation); - mteHelp.forceAndWaitForGeneration(chunkLocation); } - + @AfterEach public void reset(){ builder.reset(); diff --git a/src/test/java/org/terasology/pathfinding/PathfinderTest.java b/src/test/java/org/terasology/pathfinding/PathfinderTest.java index fc46256..85f94a3 100644 --- a/src/test/java/org/terasology/pathfinding/PathfinderTest.java +++ b/src/test/java/org/terasology/pathfinding/PathfinderTest.java @@ -13,6 +13,7 @@ import org.terasology.engine.context.Context; import org.terasology.engine.registry.InjectionHelper; import org.terasology.moduletestingenvironment.MTEExtension; +import org.terasology.moduletestingenvironment.ModuleTestingHelper; import org.terasology.moduletestingenvironment.extension.Dependencies; import org.terasology.moduletestingenvironment.extension.UseWorldGenerator; import org.terasology.navgraph.NavGraphChunk; @@ -34,8 +35,8 @@ public class PathfinderTest { private TextWorldBuilder builder; @BeforeEach - public void setup(Context context) { - builder = new TextWorldBuilder(context); + public void setup(Context context, ModuleTestingHelper helper) { + builder = new TextWorldBuilder(context, helper); world = new NavGraphSystem(); InjectionHelper.inject(world); From 5766b74e4366ee950b4f10dfaed6d63eaf0715d0 Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Sun, 29 Aug 2021 20:39:03 -0700 Subject: [PATCH 4/4] add mte back --- .../org/terasology/navgraph/ConnectNavGraphChunkTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java index 3649ecf..cb3535d 100644 --- a/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java +++ b/src/test/java/org/terasology/navgraph/ConnectNavGraphChunkTest.java @@ -26,9 +26,9 @@ /** * @author synopia */ -//@Tag("MteTest") -//@ExtendWith(MTEExtension.class) -//@Dependencies("Pathfinding") +@Tag("MteTest") +@ExtendWith(MTEExtension.class) +@Dependencies("Pathfinding") public class ConnectNavGraphChunkTest { TextWorldBuilder builder; WorldProvider world;