From aa1efc9c6e164226d1f47fcaecd5c7cf47040943 Mon Sep 17 00:00:00 2001 From: Adam NAILI Date: Fri, 12 Jan 2018 00:21:27 +0100 Subject: Modifying BoardConverter method due to TileVec2 modification and successful tests --- .../fr/umlv/java/wallj/board/BoardConverter.java | 8 +++--- .../umlv/java/wallj/board/BoardConverterTest.java | 29 ++++++++++++++++++++-- 2 files changed, 31 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java index 0f8359b..6231875 100644 --- a/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java +++ b/src/main/java/fr/umlv/java/wallj/board/BoardConverter.java @@ -14,8 +14,8 @@ public final class BoardConverter { } public static Board worldToBoard(List blocks) { - int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1; - int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1; + int width = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getCol).max().orElse(-1) + 1; + int height = blocks.stream().map(Block::getTile).mapToInt(TileVec2::getRow).max().orElse(-1) + 1; Board.Builder builder = new Board.Builder(width, height); for (Block block : blocks) { @@ -29,9 +29,9 @@ public final class BoardConverter { int nbRow = board.getDim().getRow(); int nbCol = board.getDim().getCol(); for (int i = 0; i < nbRow; i++) { - for (int j = 0; i < nbCol; j++) { + for (int j = 0; j < nbCol; j++) { Block block; - TileVec2 location = TileVec2.of(i, j); + TileVec2 location = TileVec2.of(j,i); block = BlockFactory.build(board.getBlockTypeAt(location), location); if (block != null) { blocks.add(block); diff --git a/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java b/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java index 9574adf..ad96ea1 100644 --- a/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java +++ b/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java @@ -29,7 +29,6 @@ final class BoardConverterTest { builder.setBlockTypeAt(t2,BlockType.GARBAGE); builder.setBlockTypeAt(t3,BlockType.ROBOT); builder.setBlockTypeAt(t4,BlockType.TRASH); - Board certifiedBoard = builder.build(); blocks.add(BlockFactory.build(BlockType.WALL,t0)); @@ -37,12 +36,38 @@ final class BoardConverterTest { blocks.add(BlockFactory.build(BlockType.GARBAGE,t2)); blocks.add(BlockFactory.build(BlockType.ROBOT,t3)); blocks.add(BlockFactory.build(BlockType.TRASH,t4)); - Board board = BoardConverter.worldToBoard(blocks); Assertions.assertEquals(certifiedBoard,board); + } + + @Test + void testBoardToWorld(){ + Board.Builder builder = new Board.Builder(5,1); + TileVec2 t0 = TileVec2.of(0,0); + TileVec2 t1 = TileVec2.of(1,0); + TileVec2 t2 = TileVec2.of(2,0); + TileVec2 t3 = TileVec2.of(3,0); + TileVec2 t4 = TileVec2.of(4,0); + + builder.setBlockTypeAt(t0,BlockType.WALL); + builder.setBlockTypeAt(t1,BlockType.BOMB); + builder.setBlockTypeAt(t2,BlockType.GARBAGE); + builder.setBlockTypeAt(t3,BlockType.ROBOT); + builder.setBlockTypeAt(t4,BlockType.TRASH); + Board board = builder.build(); + + List certifiedBlocks = new LinkedList<>(); + certifiedBlocks.add(BlockFactory.build(BlockType.WALL,t0)); + certifiedBlocks.add(BlockFactory.build(BlockType.BOMB,t1)); + certifiedBlocks.add(BlockFactory.build(BlockType.GARBAGE,t2)); + certifiedBlocks.add(BlockFactory.build(BlockType.ROBOT,t3)); + certifiedBlocks.add(BlockFactory.build(BlockType.TRASH,t4)); + + List blocks = BoardConverter.boardToWorld(board); } + } -- cgit v1.2.3