aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/fr/umlv/java/wallj/board/BoardParserTest.java41
-rw-r--r--src/test/resources/maps/nonRectangular.txt3
-rw-r--r--src/test/resources/maps/smallValid.txt3
3 files changed, 47 insertions, 0 deletions
diff --git a/src/test/java/fr/umlv/java/wallj/board/BoardParserTest.java b/src/test/java/fr/umlv/java/wallj/board/BoardParserTest.java
new file mode 100644
index 0000000..fdeebbe
--- /dev/null
+++ b/src/test/java/fr/umlv/java/wallj/board/BoardParserTest.java
@@ -0,0 +1,41 @@
1package fr.umlv.java.wallj.board;
2
3import fr.umlv.java.wallj.model.BlockType;
4import org.junit.jupiter.api.Assertions;
5import org.junit.jupiter.api.Test;
6
7import java.io.IOException;
8import java.net.URISyntaxException;
9import java.nio.file.Path;
10import java.nio.file.Paths;
11
12final class BoardParserTest {
13
14 private Path getResourcePath(String str) throws URISyntaxException {
15 return Paths.get(getClass().getResource(str).toURI());
16 }
17
18 @Test
19 void testFailParseBadShape() {
20 Assertions.assertThrows(IllegalArgumentException.class, () -> {
21 BoardParser.parse(getResourcePath("/maps/nonRectangular.txt"));
22 });
23 }
24
25 @Test
26 void testParse() throws IOException, URISyntaxException {
27 BlockType W = BlockType.wALL, F = BlockType.FREE, G = BlockType.GARBAGE, T = BlockType.TRASH;
28 BlockType[][] blocks = new BlockType[][]{
29 {W, W, W, W, W, W},
30 {W, F, G, F, T, W},
31 {W, W, W, W, W, W}};
32
33 Board board = BoardParser.parse(getResourcePath("/maps/smallValid.txt"));
34
35 Assertions.assertEquals(board.getDim(), TileVec2.of(blocks.length, blocks[0].length));
36 for (int row = 0; row < blocks.length; ++row)
37 for (int col = 0; col < blocks[0].length; ++col)
38 Assertions.assertEquals(board.getBlockTypeAt(TileVec2.of(row, col)), blocks[row][col]);
39 }
40
41}
diff --git a/src/test/resources/maps/nonRectangular.txt b/src/test/resources/maps/nonRectangular.txt
new file mode 100644
index 0000000..8d834db
--- /dev/null
+++ b/src/test/resources/maps/nonRectangular.txt
@@ -0,0 +1,3 @@
1WWWWWWWWWW
2W W
3WWWWWWWWWW
diff --git a/src/test/resources/maps/smallValid.txt b/src/test/resources/maps/smallValid.txt
new file mode 100644
index 0000000..fa3a3a9
--- /dev/null
+++ b/src/test/resources/maps/smallValid.txt
@@ -0,0 +1,3 @@
1WWWWWW
2W G TW
3WWWWWW \ No newline at end of file