Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add basic pathfinding test cases (#27)
Extract many tests cases from Terasology/Behaviors#92 to tests on the pathfinding itself. Most importantly, this allows us to run these tests as unit tests instead of long-running integration tests using MTE.
- Loading branch information
1 parent
bbe6ffd
commit 660d9bc
Showing
8 changed files
with
1,366 additions
and
0 deletions.
There are no files selected for viewing
191 changes: 191 additions & 0 deletions
191
src/test/java/org/terasology/flexiblepathfinding/FallingJPSTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
// Copyright 2022 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.terasology.flexiblepathfinding; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.terasology.flexiblepathfinding.helpers.JPSTestHelper; | ||
import org.terasology.flexiblepathfinding.helpers.TestPaths; | ||
import org.terasology.flexiblepathfinding.helpers.TestWorlds; | ||
import org.terasology.flexiblepathfinding.plugins.basic.FallingPlugin; | ||
|
||
/** | ||
* Falling describes purely vertical (down) paths and does not allow for horizontal steps. | ||
* <p> | ||
* The following test cases only attempt to test that the falling plugin alone does not incorrectly find valid paths for basic movements | ||
**/ | ||
public class FallingJPSTest { | ||
|
||
@Test | ||
public void succeedDescend() throws InterruptedException { | ||
executeExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatNorth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_NORTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatSouth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_SOUTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatSouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatSouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendNorth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_NORTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendSouth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_SOUTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlyNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlyNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlySouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlySouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateSouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateSouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendNorth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_NORTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendSouth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_SOUTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlyNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlyNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlySouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlySouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateSouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateSouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
private void executeExample(String[] ground, String[] pathData) throws InterruptedException { | ||
JPSTestHelper.runTest(FallingPlugin.class, ground, pathData); | ||
} | ||
|
||
private void executeFailingExample(String[] ground, String[] pathData) throws InterruptedException { | ||
JPSTestHelper.runFailingTest(FallingPlugin.class, ground, pathData); | ||
} | ||
} |
192 changes: 192 additions & 0 deletions
192
src/test/java/org/terasology/flexiblepathfinding/LeapingJPSTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
// Copyright 2022 The Terasology Foundation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package org.terasology.flexiblepathfinding; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.terasology.flexiblepathfinding.helpers.JPSTestHelper; | ||
import org.terasology.flexiblepathfinding.helpers.TestPaths; | ||
import org.terasology.flexiblepathfinding.helpers.TestWorlds; | ||
import org.terasology.flexiblepathfinding.plugins.basic.LeapingPlugin; | ||
|
||
/** | ||
* Leaping describes purely vertical (up) paths and does not allow for horizontal steps. | ||
* <p> | ||
* The following test cases (mostly) attempt to test that the leaping plugin alone does not incorrectly find valid paths that require | ||
* horizontal steps. | ||
**/ | ||
public class LeapingJPSTest { | ||
|
||
@Test | ||
public void succeedAscend() throws InterruptedException { | ||
executeExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatNorth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_NORTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatSouth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_SOUTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_FLAT_WORLD, TestPaths.SINGLE_FLAT_STEP_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatSouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failFlatSouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_FLAT_WORLD, TestPaths.DIAGONAL_FLAT_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendNorth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_NORTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendSouth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_SOUTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_ASCENDING_STEP_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlyNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlyNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlySouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendEarlySouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateSouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failAscendLateSouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_ASCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendNorth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_NORTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendSouth() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_SOUTH_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_CROSS_ASCENDING_OUT_WORLD, TestPaths.SINGLE_DESCENDING_STEP_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlyNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlyNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlySouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendEarlySouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_CORNER_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateNorthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateNorthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_NORTH_EAST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateSouthWest() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_WEST_PATH); | ||
} | ||
|
||
@Test | ||
public void failDescendLateSouthEast() throws InterruptedException { | ||
executeFailingExample(TestWorlds.THREE_BY_THREE_OPEN_ASCENDING_FULL_OUT_WORLD, TestPaths.DIAGONAL_DESCENDING_STEP_SOUTH_EAST_PATH); | ||
} | ||
|
||
private void executeExample(String[] ground, String[] pathData) throws InterruptedException { | ||
JPSTestHelper.runTest(LeapingPlugin.class, ground, pathData); | ||
} | ||
|
||
private void executeFailingExample(String[] ground, String[] pathData) throws InterruptedException { | ||
JPSTestHelper.runFailingTest(LeapingPlugin.class, ground, pathData); | ||
} | ||
} |
Oops, something went wrong.