@Test public void testIsOccupied() throws StrategyException { Position pos = new Position(0, 0); assertFalse(board.isOccupied(pos)); board.putPieceAt(pos, new Piece(PieceType.BOMB, PlayerColor.RED)); assertTrue(board.isOccupied(pos)); board.putPieceAt(pos, Piece.WATER_PIECE); assertFalse(board.isOccupied(pos)); }
@Test public void testIsPathValid() throws StrategyException { assertTrue(board.isPathValid(new Position(3, 0), new Position(3, 5))); assertTrue(board.isPathValid(new Position(0, 3), new Position(5, 3))); board.putPieceAt(new Position(3, 3), new Piece(PieceType.BOMB, PlayerColor.RED)); assertFalse(board.isPathValid(new Position(3, 0), new Position(3, 5))); assertFalse(board.isPathValid(new Position(0, 3), new Position(5, 3))); board.putPieceAt(new Position(3, 3), Piece.WATER_PIECE); assertFalse(board.isPathValid(new Position(3, 0), new Position(3, 5))); assertFalse(board.isPathValid(new Position(0, 3), new Position(5, 3))); }
@Test public void testToString() throws StrategyException { assertEquals( "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n", board.toString()); board.putPieceAt(new Position(0, 0), new Piece(PieceType.BOMB, PlayerColor.RED)); assertEquals( "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "bNNNNN\n", board.toString()); board.putPieceAt(new Position(2, 2), new Piece(PieceType.BOMB, PlayerColor.RED)); assertEquals( "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNbNNN\n" + "NNNNNN\n" + "bNNNNN\n", board.toString()); board.putPieceAtRectangle(new Position(1, 4), new Position(0, 5), Piece.WATER_PIECE); assertEquals( "NNNNNN\n" + "NNNNNN\n" + "NNNNNN\n" + "NNbNNN\n" + "NNNNWW\n" + "bNNNWW\n", board.toString()); }
@Test public void testEqualsObject() throws StrategyException { RectangularStrategyBoard mockBoard = new RectangularStrategyBoard(6, 6); RectangularStrategyBoard differentlySizedBoard = new RectangularStrategyBoard(6, 5); assertTrue(board.equals(board)); assertTrue(board.equals(mockBoard)); mockBoard.putPieceAt(new Position(0, 0), new Piece(PieceType.SCOUT, PlayerColor.RED)); assertFalse(board.equals(mockBoard)); assertFalse(board.equals(differentlySizedBoard)); assertFalse(board.equals(new Object())); }
@Test(expected = ArrayIndexOutOfBoundsException.class) public void testPutPieceAtInvalidPosition() { board.putPieceAt(new Position(-1, 0), new Piece(PieceType.SCOUT, PlayerColor.RED)); }
@Test public void testPutPieceAt() throws StrategyException { Piece redBomb = new Piece(PieceType.BOMB, PlayerColor.RED); board.putPieceAt(new Position(0, 0), redBomb); assertTrue(redBomb == board.getPieceAt(new Position(0, 0))); }