aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorpacien2018-01-08 17:49:05 +0100
committerpacien2018-01-08 17:49:05 +0100
commit7733b7dffe5a70c578713c34bdbabafee060d80a (patch)
treee6649fa8e73ee39f78b149740c510060accf571b /src/test/java
parentf9d35e2c5e4aa1aef14ae49a0fe1a5117ab67115 (diff)
downloadwallj-7733b7dffe5a70c578713c34bdbabafee060d80a.tar.gz
Implement board parser and its tests
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/fr/umlv/java/wallj/board/BoardParserTest.java41
1 files changed, 41 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}