diff --git a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java index d80bd61..7d0d4bc 100644 --- a/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java +++ b/src/test/java/inf112/fiasko/roborally/objects/BoardTest.java @@ -10,7 +10,10 @@ import org.junit.BeforeClass; import org.junit.Test; import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; import java.util.List; +import java.util.function.Predicate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -31,6 +34,9 @@ public class BoardTest { private static Position someValidPosition8; private List robotList; private Board board; + private Board boardWithDifferentAmountOfAllTypes; + private Map wallTypeNumberMap = new HashMap<>(); + private Map tileTypeNumberMap = new HashMap<>(); @BeforeClass public static void globalSetUp() { @@ -62,6 +68,31 @@ public class BoardTest { wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST)); wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST)); board = new Board(tileGrid, wallGrid, robotList); + + Grid tileGridAllTypes = new Grid<>(6,6); + Grid wallGridAllTypes = new Grid<>(6,6); + List emptyRobotList = new ArrayList<>(); + wallGridAllTypes.setElement(1, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); + wallGridAllTypes.setElement(1, 2, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); + wallGridAllTypes.setElement(1, 3, new Wall(WallType.WALL_NORMAL, Direction.SOUTH)); + wallGridAllTypes.setElement(2, 1, new Wall(WallType.WALL_CORNER, Direction.EAST)); + wallGridAllTypes.setElement(2, 2, new Wall(WallType.WALL_CORNER, Direction.EAST)); + tileGridAllTypes.setElement(1, 1, new Tile(TileType.COGWHEEL_LEFT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 1, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 2, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 3, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(3, 4, new Tile(TileType.COGWHEEL_RIGHT, Direction.NORTH)); + tileGridAllTypes.setElement(2, 1, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 2, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 3, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 4, new Tile(TileType.TILE, Direction.WEST)); + tileGridAllTypes.setElement(2, 5, new Tile(TileType.TILE, Direction.WEST)); + wallTypeNumberMap.put(WallType.WALL_NORMAL, 3); + wallTypeNumberMap.put(WallType.WALL_CORNER, 2); + tileTypeNumberMap.put(TileType.COGWHEEL_RIGHT, 4); + tileTypeNumberMap.put(TileType.COGWHEEL_LEFT, 1); + tileTypeNumberMap.put(TileType.TILE, 5); + boardWithDifferentAmountOfAllTypes = new Board(tileGridAllTypes,wallGridAllTypes,emptyRobotList); } @Test @@ -161,4 +192,72 @@ public class BoardTest { board.respawnRobots(); assertFalse(board.isRobotAlive(robot.getRobotId())); } + + @Test + public void getPositionsOfTileOnBoardGivesCorrectAmountOfCogwheelLeftTiles() { + assertEquals((int)tileTypeNumberMap.get(TileType.COGWHEEL_LEFT), + boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT).size()); + } + + @Test + public void getPositionsOfTileOnBoardHasTypeCogwheelLeft() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getTileType(), TileType.COGWHEEL_LEFT); + } + } + + @Test + public void getPositionsOfTileOnBoardGivesCorrectAmountOfTileTiles() { + assertEquals((int)tileTypeNumberMap.get(TileType.TILE), + boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE).size()); + } + + @Test + public void getPositionsOfTileOnBoardHasTypeTile() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getTileType(), TileType.TILE); + } + } + + @Test + public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallNormalWalls() { + assertEquals((int)wallTypeNumberMap.get(WallType.WALL_NORMAL), + boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL).size()); + } + + @Test + public void getPositionsOfWallOnBoardHasTypeWallNormal() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getWallType(), WallType.WALL_NORMAL); + } + } + + @Test + public void getPositionsOfWallOnBoardGivesCorrectAmountOfWallCornerWalls() { + assertEquals((int)wallTypeNumberMap.get(WallType.WALL_CORNER), + boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER).size()); + } + + @Test + public void getPositionsOfWallOnBoardHasTypeWallCorner() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); + + for (BoardElementContainer elem : boardElemList) { + assertEquals(elem.getObject().getWallType(), WallType.WALL_CORNER); + } + } + + @Test + public void getPositionsOfWallOnBoardHasCorrect() { + List> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER); + Predicate> pred = (element) -> element.getObject().getWallType() == WallType.WALL_CORNER; + boardElemList.removeIf(pred); + assertEquals(0, boardElemList.size()); + } }