From 5615f448a69a47de0be4a4f626770cd45752384f Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 2 Feb 2018 10:52:42 +0100 Subject: Fix board converter test Signed-off-by: pacien --- .../umlv/java/wallj/board/BoardConverterTest.java | 80 ++++++++++++---------- 1 file changed, 42 insertions(+), 38 deletions(-) (limited to 'src/test/java/fr') 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 84e1938..cc5575e 100644 --- a/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java +++ b/src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java @@ -1,6 +1,8 @@ package fr.umlv.java.wallj.board; import fr.umlv.java.wallj.block.*; +import org.jbox2d.common.Vec2; +import org.jbox2d.dynamics.World; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -14,60 +16,62 @@ import java.util.stream.Collectors; final class BoardConverterTest { @Test - void testWorldToBoard(){ + void testWorldToBoard() { List blocks = new LinkedList<>(); - 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); + 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); + 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 certifiedBoard = builder.build(); - blocks.add(BlockFactory.build(BlockType.WALL,t0)); - blocks.add(BlockFactory.build(BlockType.BOMB,t1)); - blocks.add(BlockFactory.build(BlockType.GARBAGE,t2)); - blocks.add(BlockFactory.build(BlockType.ROBOT,t3)); - blocks.add(BlockFactory.build(BlockType.TRASH,t4)); + blocks.add(BlockFactory.build(BlockType.WALL, t0)); + blocks.add(BlockFactory.build(BlockType.BOMB, t1)); + blocks.add(BlockFactory.build(BlockType.GARBAGE, t2)); + blocks.add(BlockFactory.build(BlockType.ROBOT, t3)); + blocks.add(BlockFactory.build(BlockType.TRASH, t4)); + World world = new World(new Vec2()); + blocks.forEach(block -> block.link(world)); Board board = BoardConverter.worldToBoard(blocks); - Assertions.assertEquals(certifiedBoard,board); + 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); + 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); + 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)); + 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); List blockTypes = blocks.stream().map(Block::getType).collect(Collectors.toList()); - List blockTypesCertified= certifiedBlocks.stream().map(Block::getType).collect(Collectors.toList()); - Assertions.assertEquals(blockTypesCertified,blockTypes); + List blockTypesCertified = certifiedBlocks.stream().map(Block::getType).collect(Collectors.toList()); + Assertions.assertEquals(blockTypesCertified, blockTypes); } -} +} -- cgit v1.2.3