aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/fr/umlv/java/wallj/board/PathFinderTest.java39
1 files changed, 23 insertions, 16 deletions
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;
14 * @author Pacien TRAN-GIRARD 14 * @author Pacien TRAN-GIRARD
15 */ 15 */
16final class PathFinderTest { 16final class PathFinderTest {
17
18 private Path getResourcePath(String str) throws URISyntaxException { 17 private Path getResourcePath(String str) throws URISyntaxException {
19 return Paths.get(getClass().getResource(str).toURI()); 18 return Paths.get(getClass().getResource(str).toURI());
20 } 19 }
@@ -35,29 +34,37 @@ final class PathFinderTest {
35 return true; 34 return true;
36 } 35 }
37 36
38 @Test 37 private void testValidPath(Board board, TileVec2 origin, TileVec2 target) {
39 void testFailImpossibleFindPath() throws URISyntaxException, IOException {
40 Board board = BoardParser.parse(getResourcePath("/maps/island.txt"));
41 PathFinder pathFinder = new PathFinder(board); 38 PathFinder pathFinder = new PathFinder(board);
39 List<TileVec2> path = pathFinder.findPath(origin, target);
42 40
43 Assertions.assertThrows(IllegalArgumentException.class, () -> { 41 Assertions.assertEquals(path.get(0), origin);
44 pathFinder.findPath(TileVec2.of(7, 3), TileVec2.of(16, 5)); // into a wall 42 Assertions.assertEquals(path.get(path.size() - 1), target);
45 }); 43 Assertions.assertTrue(isPathConnected(path));
44 Assertions.assertTrue(path.stream().allMatch(v -> board.getBlockTypeAt(v).isTraversable()));
46 } 45 }
47 46
48 @Test 47 @Test
49 void testFindPath() throws URISyntaxException, IOException { 48 void testFindPath() throws URISyntaxException, IOException {
49 testValidPath(
50 BoardParser.parse(getResourcePath("/maps/wall.txt")),
51 TileVec2.of(4, 3),
52 TileVec2.of(6, 3));
53
54 testValidPath(
55 BoardParser.parse(getResourcePath("/maps/island.txt")),
56 TileVec2.of(7, 3),
57 TileVec2.of(33, 4));
58 }
59
60
61 @Test
62 void testFailImpossibleFindPath() throws URISyntaxException, IOException {
50 Board board = BoardParser.parse(getResourcePath("/maps/island.txt")); 63 Board board = BoardParser.parse(getResourcePath("/maps/island.txt"));
51 PathFinder pathFinder = new PathFinder(board); 64 PathFinder pathFinder = new PathFinder(board);
52 65
53 TileVec2 origin = TileVec2.of(7, 3); 66 Assertions.assertThrows(IllegalArgumentException.class, () -> {
54 TileVec2 target = TileVec2.of(33, 4); 67 pathFinder.findPath(TileVec2.of(7, 3), TileVec2.of(16, 5)); // into a wall
55 List<TileVec2> path = pathFinder.findPath(origin, target); 68 });
56
57 Assertions.assertEquals(path.get(0), origin);
58 Assertions.assertEquals(path.get(path.size() - 1), target);
59 Assertions.assertTrue(isPathConnected(path));
60 Assertions.assertTrue(path.stream().allMatch(v -> board.getBlockTypeAt(v).isTraversable()));
61 } 69 }
62
63} 70}