From 7733b7dffe5a70c578713c34bdbabafee060d80a Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 8 Jan 2018 17:49:05 +0100 Subject: Implement board parser and its tests Signed-off-by: pacien --- .../fr/umlv/java/wallj/board/BoardParserTest.java | 41 ++++++++++++++++++++++ src/test/resources/maps/nonRectangular.txt | 3 ++ src/test/resources/maps/smallValid.txt | 3 ++ 3 files changed, 47 insertions(+) create mode 100644 src/test/java/fr/umlv/java/wallj/board/BoardParserTest.java create mode 100644 src/test/resources/maps/nonRectangular.txt create mode 100644 src/test/resources/maps/smallValid.txt (limited to 'src/test') 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 @@ +package fr.umlv.java.wallj.board; + +import fr.umlv.java.wallj.model.BlockType; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; + +final class BoardParserTest { + + private Path getResourcePath(String str) throws URISyntaxException { + return Paths.get(getClass().getResource(str).toURI()); + } + + @Test + void testFailParseBadShape() { + Assertions.assertThrows(IllegalArgumentException.class, () -> { + BoardParser.parse(getResourcePath("/maps/nonRectangular.txt")); + }); + } + + @Test + void testParse() throws IOException, URISyntaxException { + BlockType W = BlockType.wALL, F = BlockType.FREE, G = BlockType.GARBAGE, T = BlockType.TRASH; + BlockType[][] blocks = new BlockType[][]{ + {W, W, W, W, W, W}, + {W, F, G, F, T, W}, + {W, W, W, W, W, W}}; + + Board board = BoardParser.parse(getResourcePath("/maps/smallValid.txt")); + + Assertions.assertEquals(board.getDim(), TileVec2.of(blocks.length, blocks[0].length)); + for (int row = 0; row < blocks.length; ++row) + for (int col = 0; col < blocks[0].length; ++col) + Assertions.assertEquals(board.getBlockTypeAt(TileVec2.of(row, col)), blocks[row][col]); + } + +} 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 @@ +WWWWWWWWWW +W W +WWWWWWWWWW 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 @@ +WWWWWW +W G TW +WWWWWW \ No newline at end of file -- cgit v1.2.3