mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-06-27 19:54:43 +02:00
Merge branch 'master' of https://github.com/inf112-v20/Fiasko
This commit is contained in:
@ -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<Robot> robotList;
|
||||
private Board board;
|
||||
private Board boardWithDifferentAmountOfAllTypes;
|
||||
private Map<WallType,Integer> wallTypeNumberMap = new HashMap<>();
|
||||
private Map<TileType,Integer> tileTypeNumberMap = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void globalSetUp() {
|
||||
@ -61,7 +67,51 @@ public class BoardTest {
|
||||
wallGrid.setElement(2, 1, new Wall(WallType.WALL_NORMAL, Direction.SOUTH));
|
||||
wallGrid.setElement(2, 2, new Wall(WallType.WALL_NORMAL, Direction.EAST));
|
||||
wallGrid.setElement(1, 2, new Wall(WallType.WALL_CORNER, Direction.NORTH_EAST));
|
||||
tileGrid.setElement(3,3, new Tile(TileType.FLAG_1, Direction.NORTH));
|
||||
tileGrid.setElement(2,2, new Tile(TileType.FLAG_2, Direction.NORTH));
|
||||
board = new Board(tileGrid, wallGrid, robotList);
|
||||
|
||||
Grid<Tile> tileGridAllTypes = new Grid<>(6,6);
|
||||
Grid<Wall> wallGridAllTypes = new Grid<>(6,6);
|
||||
List<Robot> 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
|
||||
public void flagGetsUpdatedOnRobotWithCorrectLastVisitedFlag() {
|
||||
Robot testRobot = robotList.get(6);
|
||||
assertEquals(0,testRobot.getLastFlagVisited());
|
||||
board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_1);
|
||||
assertEquals(1,testRobot.getLastFlagVisited());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void flagDoesNotUpdatedOnRobotWithWringLastVisitedFlag() {
|
||||
Robot testRobot = robotList.get(6);
|
||||
assertEquals(0,testRobot.getLastFlagVisited());
|
||||
board.updateFlagOnRobot(RobotID.ROBOT_7, TileType.FLAG_2);
|
||||
assertEquals(0,testRobot.getLastFlagVisited());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -161,4 +211,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<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.COGWHEEL_LEFT);
|
||||
|
||||
for (BoardElementContainer<Tile> 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<BoardElementContainer<Tile>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfTileOnBoard(TileType.TILE);
|
||||
|
||||
for (BoardElementContainer<Tile> 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<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_NORMAL);
|
||||
|
||||
for (BoardElementContainer<Wall> 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<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
|
||||
|
||||
for (BoardElementContainer<Wall> elem : boardElemList) {
|
||||
assertEquals(elem.getObject().getWallType(), WallType.WALL_CORNER);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPositionsOfWallOnBoardHasCorrect() {
|
||||
List<BoardElementContainer<Wall>> boardElemList = boardWithDifferentAmountOfAllTypes.getPositionsOfWallOnBoard(WallType.WALL_CORNER);
|
||||
Predicate<BoardElementContainer<Wall>> pred = (element) -> element.getObject().getWallType() == WallType.WALL_CORNER;
|
||||
boardElemList.removeIf(pred);
|
||||
assertEquals(0, boardElemList.size());
|
||||
}
|
||||
}
|
||||
|
@ -4,106 +4,76 @@ import inf112.fiasko.roborally.element_properties.Action;
|
||||
import inf112.fiasko.roborally.element_properties.RobotID;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class PlayerTest {
|
||||
private Player playerTest;
|
||||
private List<ProgrammingCard> cards = new ArrayList();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
List<ProgrammingCard> cards = new ArrayList();
|
||||
cards.add(new ProgrammingCard(10, Action.MOVE_1));
|
||||
cards.add(new ProgrammingCard(20, Action.MOVE_2));
|
||||
cards.add(new ProgrammingCard(30, Action.MOVE_3));
|
||||
cards.add(new ProgrammingCard(40, Action.BACK_UP));
|
||||
cards.add(new ProgrammingCard(50, Action.ROTATE_LEFT));
|
||||
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
|
||||
playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" ,playerDeck);
|
||||
playerTest = new Player(RobotID.ROBOT_1, "TestPlayer" );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPowerDownStatusToTrue() {
|
||||
playerTest.setPowerDownNextRound(true);
|
||||
assertEquals(true, playerTest.getPowerDownNextRound());
|
||||
assertTrue(playerTest.getPowerDownNextRound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPowerDownStatusToFalse() {
|
||||
playerTest.setPowerDownNextRound(false);
|
||||
assertEquals(false, playerTest.getPowerDownNextRound());
|
||||
assertFalse(playerTest.getPowerDownNextRound());
|
||||
}
|
||||
@Test
|
||||
public void testSetInProgram(){
|
||||
playerTest.setInProgram(cards);
|
||||
assertEquals(Action.MOVE_1, playerTest.getProgramFromPlayer().get(0).getAction());
|
||||
assertEquals(Action.MOVE_2, playerTest.getProgramFromPlayer().get(1).getAction());
|
||||
assertEquals(Action.MOVE_3, playerTest.getProgramFromPlayer().get(2).getAction());
|
||||
assertEquals(Action.BACK_UP, playerTest.getProgramFromPlayer().get(3).getAction());
|
||||
}
|
||||
|
||||
@Test (expected = IllegalArgumentException.class)
|
||||
public void testSetInProgramWithToManyCards(){
|
||||
cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT));
|
||||
playerTest.setInProgram(cards);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cardGetsInsertedIntoProgram() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
}
|
||||
@Test
|
||||
public void addMultipuleCards(){
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23452342,Action.MOVE_3));
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction());
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction());
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void addTooManyCardsGetsAError() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523242,Action.MOVE_3));
|
||||
}
|
||||
@Test
|
||||
public void removeCardsFromPlayerProgram() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3));
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction());
|
||||
playerTest.removeProgramCard(4);
|
||||
assertEquals(null,playerTest.getProgram().get(4));
|
||||
}
|
||||
@Test
|
||||
public void removeAllCardsFromPlayerProgram() {
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(30,Action.MOVE_2));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(234523423,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(2342342,Action.MOVE_3));
|
||||
playerTest.setCardInProgram(new ProgrammingCard(23432342,Action.MOVE_3));
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(4).getAction());
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(3).getAction());
|
||||
assertEquals(Action.MOVE_3,playerTest.getProgram().get(2).getAction());
|
||||
assertEquals(Action.MOVE_2,playerTest.getProgram().get(1).getAction());
|
||||
assertEquals(Action.MOVE_1,playerTest.getProgram().get(0).getAction());
|
||||
playerTest.removeProgramCard(4);
|
||||
playerTest.removeProgramCard(3);
|
||||
playerTest.removeProgramCard(2);
|
||||
playerTest.removeProgramCard(1);
|
||||
playerTest.removeProgramCard(0);
|
||||
assertEquals(null,playerTest.getProgram().get(4));
|
||||
assertEquals(null,playerTest.getProgram().get(3));
|
||||
assertEquals(null,playerTest.getProgram().get(2));
|
||||
assertEquals(null,playerTest.getProgram().get(1));
|
||||
assertEquals(null,playerTest.getProgram().get(0));
|
||||
public void testSetInDeck(){
|
||||
cards.add(new ProgrammingCard(10,Action.ROTATE_LEFT));
|
||||
ProgrammingCardDeck playerDeck = new ProgrammingCardDeck(cards);
|
||||
playerTest.setPlayerDeck(playerDeck);
|
||||
assertEquals(playerDeck , playerTest.getPlayerDeck());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getErrorIfYouRemoveMoreThenIndexFive(){
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.removeProgramCard(5);
|
||||
|
||||
@Test
|
||||
public void GetPlayerRobotId(){
|
||||
assertEquals(RobotID.ROBOT_1, playerTest.getRobotID());
|
||||
}
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void getErrorIfYouRemoveANegativIndex(){
|
||||
playerTest.setCardInProgram(new ProgrammingCard(10,Action.MOVE_1));
|
||||
playerTest.removeProgramCard(-1);
|
||||
|
||||
@Test
|
||||
public void GetPlayerName(){
|
||||
assertEquals("TestPlayer", playerTest.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void GetProgramFromPlayer(){
|
||||
playerTest.setInProgram(cards);
|
||||
assertEquals(cards,playerTest.getProgram());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user