aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/fr
diff options
context:
space:
mode:
authorpacien2018-02-02 10:52:42 +0100
committerpacien2018-02-02 10:52:42 +0100
commit5615f448a69a47de0be4a4f626770cd45752384f (patch)
tree0831fa221cc34b39b7e0a7ab09b6ca51bb8e3605 /src/test/java/fr
parent48ecf24862fc9d9314e81d877dd3fcc3b7f9c894 (diff)
downloadwallj-5615f448a69a47de0be4a4f626770cd45752384f.tar.gz
Fix board converter test
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/test/java/fr')
-rw-r--r--src/test/java/fr/umlv/java/wallj/board/BoardConverterTest.java80
1 files changed, 42 insertions, 38 deletions
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 @@
1package fr.umlv.java.wallj.board; 1package fr.umlv.java.wallj.board;
2 2
3import fr.umlv.java.wallj.block.*; 3import fr.umlv.java.wallj.block.*;
4import org.jbox2d.common.Vec2;
5import org.jbox2d.dynamics.World;
4import org.junit.jupiter.api.Assertions; 6import org.junit.jupiter.api.Assertions;
5import org.junit.jupiter.api.Test; 7import org.junit.jupiter.api.Test;
6 8
@@ -14,60 +16,62 @@ import java.util.stream.Collectors;
14final class BoardConverterTest { 16final class BoardConverterTest {
15 17
16 @Test 18 @Test
17 void testWorldToBoard(){ 19 void testWorldToBoard() {
18 List<Block> blocks = new LinkedList<>(); 20 List<Block> blocks = new LinkedList<>();
19 Board.Builder builder = new Board.Builder(5,1); 21 Board.Builder builder = new Board.Builder(5, 1);
20 TileVec2 t0 = TileVec2.of(0,0); 22 TileVec2 t0 = TileVec2.of(0, 0);
21 TileVec2 t1 = TileVec2.of(1,0); 23 TileVec2 t1 = TileVec2.of(1, 0);
22 TileVec2 t2 = TileVec2.of(2,0); 24 TileVec2 t2 = TileVec2.of(2, 0);
23 TileVec2 t3 = TileVec2.of(3,0); 25 TileVec2 t3 = TileVec2.of(3, 0);
24 TileVec2 t4 = TileVec2.of(4,0); 26 TileVec2 t4 = TileVec2.of(4, 0);
25 27
26 builder.setBlockTypeAt(t0,BlockType.WALL); 28 builder.setBlockTypeAt(t0, BlockType.WALL);
27 builder.setBlockTypeAt(t1,BlockType.BOMB); 29 builder.setBlockTypeAt(t1, BlockType.BOMB);
28 builder.setBlockTypeAt(t2,BlockType.GARBAGE); 30 builder.setBlockTypeAt(t2, BlockType.GARBAGE);
29 builder.setBlockTypeAt(t3,BlockType.ROBOT); 31 builder.setBlockTypeAt(t3, BlockType.ROBOT);
30 builder.setBlockTypeAt(t4,BlockType.TRASH); 32 builder.setBlockTypeAt(t4, BlockType.TRASH);
31 Board certifiedBoard = builder.build(); 33 Board certifiedBoard = builder.build();
32 34
33 blocks.add(BlockFactory.build(BlockType.WALL,t0)); 35 blocks.add(BlockFactory.build(BlockType.WALL, t0));
34 blocks.add(BlockFactory.build(BlockType.BOMB,t1)); 36 blocks.add(BlockFactory.build(BlockType.BOMB, t1));
35 blocks.add(BlockFactory.build(BlockType.GARBAGE,t2)); 37 blocks.add(BlockFactory.build(BlockType.GARBAGE, t2));
36 blocks.add(BlockFactory.build(BlockType.ROBOT,t3)); 38 blocks.add(BlockFactory.build(BlockType.ROBOT, t3));
37 blocks.add(BlockFactory.build(BlockType.TRASH,t4)); 39 blocks.add(BlockFactory.build(BlockType.TRASH, t4));
40 World world = new World(new Vec2());
41 blocks.forEach(block -> block.link(world));
38 Board board = BoardConverter.worldToBoard(blocks); 42 Board board = BoardConverter.worldToBoard(blocks);
39 43
40 Assertions.assertEquals(certifiedBoard,board); 44 Assertions.assertEquals(certifiedBoard, board);
41 } 45 }
42 46
43 @Test 47 @Test
44 void testBoardToWorld(){ 48 void testBoardToWorld() {
45 Board.Builder builder = new Board.Builder(5,1); 49 Board.Builder builder = new Board.Builder(5, 1);
46 TileVec2 t0 = TileVec2.of(0,0); 50 TileVec2 t0 = TileVec2.of(0, 0);
47 TileVec2 t1 = TileVec2.of(1,0); 51 TileVec2 t1 = TileVec2.of(1, 0);
48 TileVec2 t2 = TileVec2.of(2,0); 52 TileVec2 t2 = TileVec2.of(2, 0);
49 TileVec2 t3 = TileVec2.of(3,0); 53 TileVec2 t3 = TileVec2.of(3, 0);
50 TileVec2 t4 = TileVec2.of(4,0); 54 TileVec2 t4 = TileVec2.of(4, 0);
51 55
52 builder.setBlockTypeAt(t0,BlockType.WALL); 56 builder.setBlockTypeAt(t0, BlockType.WALL);
53 builder.setBlockTypeAt(t1,BlockType.BOMB); 57 builder.setBlockTypeAt(t1, BlockType.BOMB);
54 builder.setBlockTypeAt(t2,BlockType.GARBAGE); 58 builder.setBlockTypeAt(t2, BlockType.GARBAGE);
55 builder.setBlockTypeAt(t3,BlockType.ROBOT); 59 builder.setBlockTypeAt(t3, BlockType.ROBOT);
56 builder.setBlockTypeAt(t4,BlockType.TRASH); 60 builder.setBlockTypeAt(t4, BlockType.TRASH);
57 Board board = builder.build(); 61 Board board = builder.build();
58 62
59 List<Block> certifiedBlocks = new LinkedList<>(); 63 List<Block> certifiedBlocks = new LinkedList<>();
60 64
61 certifiedBlocks.add(BlockFactory.build(BlockType.WALL,t0)); 65 certifiedBlocks.add(BlockFactory.build(BlockType.WALL, t0));
62 certifiedBlocks.add(BlockFactory.build(BlockType.BOMB,t1)); 66 certifiedBlocks.add(BlockFactory.build(BlockType.BOMB, t1));
63 certifiedBlocks.add(BlockFactory.build(BlockType.GARBAGE,t2)); 67 certifiedBlocks.add(BlockFactory.build(BlockType.GARBAGE, t2));
64 certifiedBlocks.add(BlockFactory.build(BlockType.ROBOT,t3)); 68 certifiedBlocks.add(BlockFactory.build(BlockType.ROBOT, t3));
65 certifiedBlocks.add(BlockFactory.build(BlockType.TRASH,t4)); 69 certifiedBlocks.add(BlockFactory.build(BlockType.TRASH, t4));
66 70
67 List<Block> blocks = BoardConverter.boardToWorld(board); 71 List<Block> blocks = BoardConverter.boardToWorld(board);
68 List<BlockType> blockTypes = blocks.stream().map(Block::getType).collect(Collectors.toList()); 72 List<BlockType> blockTypes = blocks.stream().map(Block::getType).collect(Collectors.toList());
69 List<BlockType> blockTypesCertified= certifiedBlocks.stream().map(Block::getType).collect(Collectors.toList()); 73 List<BlockType> blockTypesCertified = certifiedBlocks.stream().map(Block::getType).collect(Collectors.toList());
70 Assertions.assertEquals(blockTypesCertified,blockTypes); 74 Assertions.assertEquals(blockTypesCertified, blockTypes);
71 } 75 }
72}
73 76
77}