diff options
author | pacien | 2018-02-03 20:58:28 +0100 |
---|---|---|
committer | pacien | 2018-02-03 20:58:28 +0100 |
commit | 6bbef8efd0748d7ebd71c8e17b90ac7f407e4575 (patch) | |
tree | 430f50a67de2b913a9d859cf24442982a7a599ba /src/test | |
parent | e86f5e3c3e197aee8899f643d026dcf4468fbd84 (diff) | |
download | wallj-6bbef8efd0748d7ebd71c8e17b90ac7f407e4575.tar.gz |
Fix path finder incorrect behaviour
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/fr/umlv/java/wallj/board/PathFinderTest.java | 39 | ||||
-rw-r--r-- | src/test/resources/maps/wall.txt | 7 |
2 files changed, 30 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 | */ |
16 | final class PathFinderTest { | 16 | final 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 | } |
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 @@ | |||
1 | WWWWWWWWWWW | ||
2 | W W | ||
3 | W W W | ||
4 | W W W | ||
5 | W W W | ||
6 | W W | ||
7 | WWWWWWWWWWW \ No newline at end of file | ||