From 6bbef8efd0748d7ebd71c8e17b90ac7f407e4575 Mon Sep 17 00:00:00 2001 From: pacien Date: Sat, 3 Feb 2018 20:58:28 +0100 Subject: Fix path finder incorrect behaviour Signed-off-by: pacien --- .../fr/umlv/java/wallj/board/PathFinderTest.java | 39 +++++++++++++--------- src/test/resources/maps/wall.txt | 7 ++++ 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 src/test/resources/maps/wall.txt (limited to 'src/test') diff --git a/src/test/java/fr/umlv/java/wallj/board/PathFinderTest.java b/src/test/java/fr/umlv/java/wallj/board/PathFinderTest.java index be615b7..ddacf71 100644 --- a/src/test/java/fr/umlv/java/wallj/board/PathFinderTest.java +++ b/src/test/java/fr/umlv/java/wallj/board/PathFinderTest.java @@ -14,7 +14,6 @@ import java.util.List; * @author Pacien TRAN-GIRARD */ final class PathFinderTest { - private Path getResourcePath(String str) throws URISyntaxException { return Paths.get(getClass().getResource(str).toURI()); } @@ -35,29 +34,37 @@ final class PathFinderTest { return true; } - @Test - void testFailImpossibleFindPath() throws URISyntaxException, IOException { - Board board = BoardParser.parse(getResourcePath("/maps/island.txt")); + private void testValidPath(Board board, TileVec2 origin, TileVec2 target) { PathFinder pathFinder = new PathFinder(board); + List path = pathFinder.findPath(origin, target); - Assertions.assertThrows(IllegalArgumentException.class, () -> { - pathFinder.findPath(TileVec2.of(7, 3), TileVec2.of(16, 5)); // into a wall - }); + Assertions.assertEquals(path.get(0), origin); + Assertions.assertEquals(path.get(path.size() - 1), target); + Assertions.assertTrue(isPathConnected(path)); + Assertions.assertTrue(path.stream().allMatch(v -> board.getBlockTypeAt(v).isTraversable())); } @Test void testFindPath() throws URISyntaxException, IOException { + testValidPath( + BoardParser.parse(getResourcePath("/maps/wall.txt")), + TileVec2.of(4, 3), + TileVec2.of(6, 3)); + + testValidPath( + BoardParser.parse(getResourcePath("/maps/island.txt")), + TileVec2.of(7, 3), + TileVec2.of(33, 4)); + } + + + @Test + void testFailImpossibleFindPath() throws URISyntaxException, IOException { Board board = BoardParser.parse(getResourcePath("/maps/island.txt")); PathFinder pathFinder = new PathFinder(board); - TileVec2 origin = TileVec2.of(7, 3); - TileVec2 target = TileVec2.of(33, 4); - List path = pathFinder.findPath(origin, target); - - Assertions.assertEquals(path.get(0), origin); - Assertions.assertEquals(path.get(path.size() - 1), target); - Assertions.assertTrue(isPathConnected(path)); - Assertions.assertTrue(path.stream().allMatch(v -> board.getBlockTypeAt(v).isTraversable())); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + pathFinder.findPath(TileVec2.of(7, 3), TileVec2.of(16, 5)); // into a wall + }); } - } diff --git a/src/test/resources/maps/wall.txt b/src/test/resources/maps/wall.txt new file mode 100644 index 0000000..97a5874 --- /dev/null +++ b/src/test/resources/maps/wall.txt @@ -0,0 +1,7 @@ +WWWWWWWWWWW +W W +W W W +W W W +W W W +W W +WWWWWWWWWWW \ No newline at end of file -- cgit v1.2.3