Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: minor tweaks and adjustments to test #66

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/test/java/org/terasology/TextWorldBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,24 @@
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 org.terasology.moduletestingenvironment.ModuleTestingHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
* Created by synopia on 11.02.14.
Expand All @@ -26,11 +32,14 @@ public class TextWorldBuilder {
private WorldProvider world;
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);
Expand All @@ -40,12 +49,22 @@ 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);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,9 +133,14 @@ 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);
}


@AfterEach
public void reset(){
builder.reset();
}

private void assertCenter(final NavGraphChunk center, NavGraphChunk left, NavGraphChunk up, NavGraphChunk right, NavGraphChunk down, String[] contours) {
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/org/terasology/navgraph/ContourFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -416,9 +417,14 @@ 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);
}


@AfterEach
public void reset(){
builder.reset();
}

private void assertContour(String[] ground, String[] contour) {
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/org/terasology/navgraph/FloorFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -303,9 +304,13 @@ 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
public void reset(){
builder.reset();
}

private void assertFloors(String[] data, String[] floors) {
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/org/terasology/navgraph/RegionFinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,9 +151,13 @@ 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
public void reset(){
builder.reset();
}

private void assertRegions(String[] data, String[] regions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -230,8 +231,12 @@ 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
public void reset(){
builder.reset();
}
}
9 changes: 7 additions & 2 deletions src/test/java/org/terasology/pathfinding/HAStarLoSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -138,9 +139,13 @@ 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
public void reset(){
builder.reset();
}

private void executeExample(String[] ground, String[] pathData) {
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/org/terasology/pathfinding/HAStarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,9 +42,13 @@ 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();
}

@Test
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/terasology/pathfinding/PathfinderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,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;
Expand All @@ -33,15 +35,20 @@ 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);

pathfinder = new Pathfinder(world, null);
}

@AfterEach
public void reset(){
builder.reset();
}

@Test
public void test() {
world.updateChunk(new Vector3i(0, 0, 0));
Expand Down