package chess; import junit.framework.*; import java.util.Vector; /* * ProcessedLineTest.java * JUnit based test * * Created on February 10, 2007, 5:13 PM */ /** * * @author Stanislav Hromek */ public class MoveTest extends TestCase { public MoveTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(MoveTest.class); return suite; } public void testGetMoveNumber() { System.out.println("getMoveNumber"); Move move = new Move(5, "e2-e4", "e7-e5"); int expResult = 5; int result = move.getMoveNumber(); assertEquals(expResult, result); } public void testGetWhiteMove() { System.out.println("getWhiteMove"); Move move = new Move(1, "e2-e4", "e7-e5"); String expResult = "e2-e4"; String result = move.getWhiteMove(); assertEquals(expResult, result); } public void testGetBlackMove() { System.out.println("getBlackMove"); Move move = new Move(1, "e2-e4", "e7-e5"); String expResult = "e7-e5"; String result = move.getBlackMove(); assertEquals(expResult, result); } public void testIsMovePossible() { System.out.println("isMovePossible"); Move move = new Move(1, "e2-e4", "e7-e5"); Board board = new Board(); board.getSquare("e2").setPiece(new Pawn("white")); board.getSquare("e7").setPiece(new Pawn("black")); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); assertEquals("1", true, move.isMovePossible(board, "white", currentMoveInfo)); assertEquals("2", true, move.isMovePossible(board, "black", currentMoveInfo)); } public void testGetMovingPiece() { System.out.println("getMovingPiece"); Move instance = new Move(1, "e2-e4", "e7-e5"); String move = "e2-e4"; assertEquals("pawn", instance.getMovingPiece(move)); move = "Re2-e4"; assertEquals("rook", instance.getMovingPiece(move)); move = "Kne2-e4"; assertEquals("knight", instance.getMovingPiece(move)); move = "Be2-e4"; assertEquals("bishop", instance.getMovingPiece(move)); move = "Qe2-e4"; assertEquals("queen", instance.getMovingPiece(move)); move = "Ke4"; assertEquals("king", instance.getMovingPiece(move)); move = "SSe2-e4"; assertEquals(null, instance.getMovingPiece(move)); } public void testPlayMove() { System.out.println("playMove"); Board board = new Board(); board.setTheStartingPosition(); Move move = new Move(1, "e2-e4", "e7-e5"); Move move2 = new Move(2, "Kng1-f3", "Knb8-c6"); assertEquals(true, move.playMove(board, 1, "white")); assertEquals(true, move.playMove(board, 1, "black")); assertEquals(true, move2.playMove(board, 2, "white")); assertEquals(true, move2.playMove(board, 2, "black")); } public void testExtractInfoFromString() { System.out.println("extractInfoFromString"); String color = "white"; Move move = new Move(1, "e2-e4", "e7-e5"); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); assertEquals("1", Move.LONG_NOTATION, currentMoveInfo.notation); assertEquals("2", true, currentMoveInfo.result); } public void testExtractInfoFromString2() { System.out.println("extractInfoFromString2"); Game game = new Game(); String color = "white"; Move move = new Move(1, "e4", "e5"); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); System.out.println("Game error = "+Game.errorMessage); assertEquals("1", Move.SHORT_NOTATION, currentMoveInfo.notation); assertEquals("2", true, currentMoveInfo.result); } public void testExtractInfoFromString3() { System.out.println("extractInfoFromString3"); Game game = new Game(); String color = "white"; Move move = new Move(1, "exd5", "Knd5"); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); System.out.println("Game error = "+Game.errorMessage); assertEquals("1", Move.SHORT_NOTATION, currentMoveInfo.notation); assertEquals("2", true, currentMoveInfo.result); assertEquals("3", "exchange", currentMoveInfo.action); assertEquals("4", "e", currentMoveInfo.movePieceFrom); assertEquals("5", "d5", currentMoveInfo.movePieceTo); } public void testGetStartSquare() { System.out.println("getStartSquare"); Move instance = new Move(1, "e2-e4", "e7-e5"); String move = "e2"; assertEquals("e2", instance.getStartSquare(move)); move = "g7"; assertEquals("g7", instance.getStartSquare(move)); move = "e2"; assertEquals("e2", instance.getStartSquare(move)); move = "Be2-f3+"; assertEquals(null, instance.getStartSquare(move)); } public void testBlackOrWhite() { System.out.println("blackOrWhite"); String color = "white"; Move instance = new Move(1, "e2-e4", "e7-e5"); String expResult = "e2-e4"; String result = instance.blackOrWhite(color); assertEquals(expResult, result); color = "black"; result = instance.blackOrWhite(color); assertEquals("e7-e5", result); } public void testGetEndSquare() { System.out.println("getEndSquare"); Move instance = new Move(1, "e2-e4", "e7-e5"); String move = "e2-e4"; assertEquals("e4", instance.getEndSquare(move)); move = "g7-h5"; assertEquals("h5", instance.getEndSquare(move)); move = "e2-f3"; assertEquals("f3", instance.getEndSquare(move)); move = "e2-f3"; assertEquals("f3", instance.getEndSquare(move)); } public void testGetStartSquare2() { System.out.println("getStartSquare2"); Move instance = new Move(1, "e4", "e5"); String move = "e4"; assertEquals("e4", instance.getStartSquare(move)); move = "7"; assertEquals("7", instance.getStartSquare(move)); move = "f3"; assertEquals("f3", instance.getStartSquare(move)); move = ""; assertEquals("", instance.getStartSquare(move)); move = "e"; assertEquals("e", instance.getStartSquare(move)); move = "a"; assertEquals("a", instance.getStartSquare(move)); move = "aaa"; assertEquals(null, instance.getStartSquare(move)); } public void testGetEndSquare2() { System.out.println("getEndSquare2"); // moveWithoutPiece Move instance = new Move(1, "e4", "e5"); String move = "e4"; assertEquals("e4", instance.getEndSquare(move)); move = "h5-h6"; assertEquals("h6", instance.getEndSquare(move)); move = "f3"; assertEquals("f3", instance.getEndSquare(move)); move = "gf3"; assertEquals("f3", instance.getEndSquare(move)); move = "exd5"; assertEquals("d5", instance.getEndSquare(move)); } public void testGetAction() { System.out.println("getAction"); Move instance = new Move(1, "e2-e4", "e7-e5"); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); String move = "e2-"; String result = instance.getAction(move, currentMoveInfo); assertEquals("1", "move", result); move = "e2x"; result = instance.getAction(move, currentMoveInfo); assertEquals("2", "exchange", result); move = ""; result = instance.getAction(move, currentMoveInfo); assertEquals("3", "move", result); } public void testIsStartingPositionOk() { System.out.println("isStartingPositionOk"); Board board = new Board(); board.setTheStartingPosition(); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(1, "0-0", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); Piece king = board.getSquare("e1").getPiece(); assertEquals(true, king instanceof King); assertEquals(false, ((King)king).hasMoved()); Piece rook = board.getSquare("h1").getPiece(); assertEquals(true, rook instanceof Rook); assertEquals(false, ((Rook)rook).hasMoved()); CurrentMoveInfo result = move.isStartingPositionOk(board, color, currentMoveInfo); assertEquals("e1", result.movePieceFrom); assertEquals("h1", result.movePieceFromTwo); assertEquals(true, result.result); move = new Move(1, "0-0", "Re7-e5"); board.getSquare("e7").setPiece(new Queen("black")); color = "black"; currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); //System.out.println("currentMovingPiece = "+currentMoveInfo.currentMovingPiece); result = move.isStartingPositionOk(board, color, currentMoveInfo); assertEquals(false, result.result); assertEquals("e7", result.movePieceFrom); } public void testGetStartSquaresForCastle() { System.out.println("getStartSquaresForCastle"); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(8, "0-0", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); // currentMoveInfo.action = move.getAction(color); CurrentMoveInfo result = move.getStartSquaresForCastle(color, currentMoveInfo); assertEquals("e1", result.movePieceFrom); assertEquals("h1", result.movePieceFromTwo); } public void testIsStartingPositionOkTwo() { System.out.println("isStartingPositionOkTwo"); Board board = new Board(); Move move = new Move(8, "Qe3-e7", "Re7-e5"); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); // ok boolean result = move.isStartingPositionOkTwo(currentMoveInfo.currentMovingPiece, color, ((Piece)new Queen(color)), board.getSquare(currentMoveInfo.movePieceFrom), currentMoveInfo.isErrorMessageAllowed); assertEquals(true, result); // no piece on square result = move.isStartingPositionOkTwo(currentMoveInfo.currentMovingPiece, color, null, board.getSquare(currentMoveInfo.movePieceFrom), currentMoveInfo.isErrorMessageAllowed); assertEquals(false, result); // opposite color piece result = move.isStartingPositionOkTwo(currentMoveInfo.currentMovingPiece, color, ((Piece)new King("black")), board.getSquare(currentMoveInfo.movePieceFrom), currentMoveInfo.isErrorMessageAllowed); assertEquals(false, result); // not piece as expected result = move.isStartingPositionOkTwo(currentMoveInfo.currentMovingPiece, color, ((Piece)new King(color)), board.getSquare(currentMoveInfo.movePieceFrom), currentMoveInfo.isErrorMessageAllowed); assertEquals(false, result); assertEquals("In white move 8. is wrong piece on kings position", Game.errorMessage); } public void testIsEndingPositionOk() { System.out.println("isEndingPositionOk"); Board board = new Board(); board.setTheStartingPosition(); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(1, "0-0", "Re7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); Piece king = board.getSquare("e1").getPiece(); assertEquals(true, king instanceof King); assertEquals(false, ((King)king).hasMoved()); Piece rook = board.getSquare("h1").getPiece(); assertEquals(true, rook instanceof Rook); assertEquals(false, ((Rook)rook).hasMoved()); currentMoveInfo = move.isEndingPositionOk(board, color, currentMoveInfo); assertEquals("g1", currentMoveInfo.movePieceTo); assertEquals("f1", currentMoveInfo.movePieceToTwo); color = "black"; currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); currentMoveInfo = move.isEndingPositionOk(board, color, currentMoveInfo); assertEquals("rook", currentMoveInfo.currentMovingPiece); assertEquals("e5", currentMoveInfo.movePieceTo); assertEquals(true, currentMoveInfo.result); board.getSquare("e5").setPiece(new Queen("white")); currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); currentMoveInfo = move.isEndingPositionOk(board, color, currentMoveInfo); assertEquals("rook", currentMoveInfo.currentMovingPiece); assertEquals(true, currentMoveInfo.result); board.getSquare("e5").setPiece(new Queen("black")); currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); currentMoveInfo = move.isEndingPositionOk(board, color, currentMoveInfo); assertEquals("rook", currentMoveInfo.currentMovingPiece); assertEquals(false, currentMoveInfo.result); color = "white"; // Move.notationType = Move.UNKNOWN; move = new Move(1, "exd5", "Knd5"); board.getSquare("e4").setPiece(new Pawn("white")); board.getSquare("d5").setPiece(new Pawn("black")); currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); currentMoveInfo = move.isEndingPositionOk(board, color, currentMoveInfo); assertEquals("pawn", currentMoveInfo.currentMovingPiece); assertEquals(true, currentMoveInfo.result); } public void testIsEndingPositionOkTwo() { System.out.println("isEndingPositionOkTwo"); Board board = new Board(); // carefull, new board will set the pieces to init position Move move = new Move(8, "Qe3-e6", "e7-e5"); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); // empty square boolean result = move.isEndingPositionOkTwo(color, null, board.getSquare(currentMoveInfo.movePieceTo)); assertEquals(true, result); // not empty, with the same piece color result = move.isEndingPositionOkTwo(color, ((Piece)new Bishop("white")), board.getSquare(currentMoveInfo.movePieceTo)); assertEquals(false, result); assertEquals("In white move 8. is the same color piece at square e6", Game.errorMessage); // not empty, opposite color result = move.isEndingPositionOkTwo(color, ((Piece)new Bishop("black")), board.getSquare(currentMoveInfo.movePieceTo)); assertEquals(true, result); } public void testIsRoadOk() { System.out.println("isRoadOk"); Board board = new Board(); // carefull, new board will set the pieces to init position Move move = new Move(8, "Qe3-e6", "e7-e5"); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); board.getSquare("e3").setPiece(new Queen("white")); assertEquals("e3", currentMoveInfo.movePieceFrom); assertEquals("e6", currentMoveInfo.movePieceTo); assertEquals("queen", currentMoveInfo.currentMovingPiece); currentMoveInfo = move.isRoadOk(board, color, currentMoveInfo); assertEquals(true, currentMoveInfo.result); board.getSquare("e5").setPiece(new Pawn("black")); currentMoveInfo = move.isRoadOk(board, color, currentMoveInfo); assertEquals(false, currentMoveInfo.result); } public void testIsPossibleToMoveToEndSquare() { System.out.println("isPossibleToMoveToEndSquare"); Board board = new Board(); String color = "black"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); board.getSquare("e3").setPiece(new Bishop("black")); Move move = new Move(8, "Qe3-e6", "Be3-a3"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); CurrentMoveInfo result = move.isPossibleToMoveToEndSquare(board, color, currentMoveInfo); assertEquals(false, result.result); board.getSquare("a1").setPiece(new Bishop("black")); move = new Move(8, "Qe3-e6", "Ba1-h8"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); result = move.isPossibleToMoveToEndSquare(board, color, currentMoveInfo); assertEquals(true, result.result); } public void testGetEndSquaresForCastle() { System.out.println("getEndSquaresForCastle"); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(8, "0-0", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); // currentMoveInfo.action = move.getAction(color); CurrentMoveInfo result = move.getStartSquaresForCastle(color, currentMoveInfo); assertEquals("g1", result.movePieceTo); assertEquals("f1", result.movePieceToTwo); } public void testDoMove() { System.out.println("doMove"); Board board = new Board(); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(8, "0-0", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); board.getSquare("e1").setPiece(new King("white")); board.getSquare("h1").setPiece(new Rook("white")); move.doMove(board, currentMoveInfo); assertEquals(null, board.getSquare("e1").getPiece()); assertEquals(null, board.getSquare("h1").getPiece()); assertEquals("king", board.getSquare("g1").getPiece().getName()); assertEquals("rook", board.getSquare("f1").getPiece().getName()); color = "black"; currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); board.getSquare("e7").setPiece(new Pawn("black")); move.doMove(board, currentMoveInfo); assertEquals(null, board.getSquare("e7").getPiece()); assertEquals("pawn", board.getSquare("e5").getPiece().getName()); color = "white"; currentMoveInfo = new CurrentMoveInfo(); move = new Move(9, "e7-e8Q", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); board.getSquare("e7").setPiece(new Pawn("white")); move.doMove(board, currentMoveInfo); assertEquals(null, board.getSquare("e7").getPiece()); assertEquals("queen", board.getSquare("e8").getPiece().getName()); } public void testSetFlagForPawnExchange() { System.out.println("setFlagForPawnExchange"); Board board = new Board(); String color = "black"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(8, "0-0", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); boolean result = move.setFlagForPawnExchange(board, currentMoveInfo, color); assertEquals("e6", Game.previousPawnMove); } public void testIsLastLine() { System.out.println("isLastLine"); Board board = new Board(); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move move = new Move(8, "d7-d8Q", "e7-e5"); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); boolean result = move.isLastLine(color, currentMoveInfo); assertEquals(true, result); } public void testGetPromotingPiece() { System.out.println("getPromotingPiece"); Board board = new Board(); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); Move instance = new Move(8, "d7-d8Q", "e7-e5"); String move = "d7-d8Q"; String color = "white"; Piece result = instance.getPromotingPiece(move, color); assertEquals("queen", result.getName()); move = "d7-d8Kn"; color = "white"; result = instance.getPromotingPiece(move, color); assertEquals("knight", result.getName()); move = "d7-d8B"; color = "white"; result = instance.getPromotingPiece(move, color); assertEquals("bishop", result.getName()); assertEquals("white", result.getPieceColor()); move = "d7-d8R"; color = "white"; result = instance.getPromotingPiece(move, color); assertEquals("rook", result.getName()); move = "d7-d8"; color = "white"; result = instance.getPromotingPiece(move, color); assertEquals(null, result); move = "e2-e1B"; color = "black"; result = instance.getPromotingPiece(move, color); assertEquals("bishop", result.getName()); assertEquals("black", result.getPieceColor()); } public void testGetOppositeColor() { System.out.println("getOppositeColor"); String color = "white"; Move instance = new Move(8, "d7-d8B", "e7-e5"); String result = instance.getOppositeColor(color); assertEquals("black", result); } public void testIsCheck() { System.out.println("isCheck"); Board board = new Board(); String color = "white"; Move move = new Move(8, "Re5-a5", "e7-e5"); board.getSquare("e1").setPiece(new King("white")); board.getSquare("e5").setPiece(new Rook("white")); board.getSquare("e8").setPiece(new Queen("black")); boolean result = move.isCheck(board, color); assertEquals(false, result); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); move.doMove(board, currentMoveInfo); result = move.isCheck(board, color); assertEquals(true, result); } public void testIsCheck2() { System.out.println("isCheck2"); Board board = new Board(); String color = "white"; Move move = new Move(8, "e5-e6", "e7-e5"); board.getSquare("f7").setPiece(new King("black")); board.getSquare("e5").setPiece(new Pawn("white")); boolean result = move.isCheck(board, color); assertEquals(false, result); CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); move.doMove(board, currentMoveInfo); // check opposite color king check result = move.isCheck(board, move.getOppositeColor(color)); assertEquals(true, result); } public void testIsCheck3() { System.out.println("isCheck3"); // Board board = new Board(); // // String color = "white"; // Move move = new Move(8, "e5-e6", "e7-e5"); // board.getSquare("f7").setPiece(new King("black")); // board.getSquare("e5").setPiece(new Pawn("white")); // // boolean result = move.isCheck(board, color); // assertEquals(true, result); // CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); // currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); // move.doMove(board, currentMoveInfo); } public void testIsMovePossibleShort() { System.out.println("isMovePossibleShort"); Move move = new Move(1, "e4", "e5"); Board board = new Board(); board.getSquare("e2").setPiece(new Pawn("white")); board.getSquare("e7").setPiece(new Pawn("black")); String color = "white"; CurrentMoveInfo currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); assertEquals("0", "move", currentMoveInfo.getAction()); System.out.println("currentMoveInfo.notation = "+ currentMoveInfo.notation); assertEquals("1", true, move.isMovePossibleShort(board, "white", currentMoveInfo).result); // set currentMoveInfo again (was filled by previous call) color = "black"; currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); System.out.println("currentMoveInfo = "+currentMoveInfo); assertEquals("2", true, move.isMovePossibleShort(board, "black", currentMoveInfo).result); board.getSquare("e2").setPiece(null); board.getSquare("e7").setPiece(null); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); assertEquals("2", false, move.isMovePossibleShort(board, "black", currentMoveInfo).result); move = new Move(1, "exd5", "e5"); color = "white"; currentMoveInfo = new CurrentMoveInfo(); currentMoveInfo = move.extractInfoFromString(color, currentMoveInfo); board.getSquare("e4").setPiece(new Pawn("white")); board.getSquare("d5").setPiece(new Pawn("black")); } public void testAdditionalInfoFitsToSquareName() { System.out.println("additionalInfoFitsToSquareName"); Move move = new Move(1, "e2-e4", "e7-e5"); assertEquals("1", true, move.additionalInfoFitsToSquareName("", "")); assertEquals("2", false, move.additionalInfoFitsToSquareName("e", "")); assertEquals("3", false, move.additionalInfoFitsToSquareName("6", "")); assertEquals("4", true, move.additionalInfoFitsToSquareName("", "f")); assertEquals("5", true, move.additionalInfoFitsToSquareName("", "4")); assertEquals("1", true, move.additionalInfoFitsToSquareName("e", "e4")); assertEquals("2", true, move.additionalInfoFitsToSquareName("4", "e4")); assertEquals("3", false, move.additionalInfoFitsToSquareName("6", "d4")); assertEquals("4", false, move.additionalInfoFitsToSquareName("d", "f3")); assertEquals("1", true, move.additionalInfoFitsToSquareName("e4", "e4")); assertEquals("2", false, move.additionalInfoFitsToSquareName("e4", "f4")); assertEquals("3", false, move.additionalInfoFitsToSquareName("e4", "e3")); assertEquals("4", false, move.additionalInfoFitsToSquareName("a1", "h8")); assertEquals("1", true, move.additionalInfoFitsToSquareName("", "e2")); assertEquals("2", false, move.additionalInfoFitsToSquareName("e2", "")); } public void testTrimNotUsedChars() { System.out.println("trimNotUsedChars"); Move move = new Move(11, "e2!", "Q4xe7+!?"); assertEquals("1", "e2", move.trimNotUsedChars(move.getWhiteMove())); assertEquals("2", "Q4xe7", move.trimNotUsedChars(move.getBlackMove())); move = new Move(11, "Qe3-e6", "Be3-a3"); assertEquals("3", "Qe3-e6", move.trimNotUsedChars(move.getWhiteMove())); assertEquals("4", "Be3-a3", move.trimNotUsedChars(move.getBlackMove())); move = new Move(11, "Qe6", "Ba3"); assertEquals("5", "Qe6", move.trimNotUsedChars(move.getWhiteMove())); assertEquals("6", "Ba3", move.trimNotUsedChars(move.getBlackMove())); } public void testIsCastle() { System.out.println("isCastle"); String move = ""; Move instance = new Move(1, "O-O", "e7-e5"); boolean result = instance.isCastle("0-0"); assertEquals(true, result); result = instance.isCastle("0-0x0"); assertEquals(false, result); } public void testGetCastleType() { System.out.println("getCastleType"); Move instance = new Move(11, "e2!", "Q4xe7+!?"); String result = instance.getCastleType("0-0"); assertEquals("small castle", result); result = instance.getCastleType("0-0-0"); assertEquals("big castle", result); result = instance.getCastleType("0x0-0"); assertEquals(null, result); } public void testToString() { System.out.println("toString"); Move instance = new Move(11, "e2!", "Q4xe7+!?"); String result = instance.toString(); assertEquals("1", "11 e2! Q4xe7+!?", result); } public void testRemovePromotingPiece() { System.out.println("removePromotingPiece"); Move instance = new Move(11, "e2!", "Q4xe7+!?"); // some dummy instance String move = "e8Q"; String currentPromotingPiece = "queen"; String result = instance.removePromotingPiece(move, currentPromotingPiece); assertEquals("1", "e8", result); move = "e8Kn"; currentPromotingPiece = "knight"; result = instance.removePromotingPiece(move, currentPromotingPiece); assertEquals("2", "e8", result); move = "e8"; currentPromotingPiece = "dummy"; result = instance.removePromotingPiece(move, currentPromotingPiece); assertEquals("3", "e8", result); move = "e8=Q"; currentPromotingPiece = "queen"; result = instance.removePromotingPiece(move, currentPromotingPiece); assertEquals("4", "e8", result); } public void testRemovePiece() { System.out.println("removePiece"); Move instance = new Move(11, "e2!", "Q4xe7+!?"); // some dummy instance String move = "Kne2-e4"; String currentMovingPiece = "knight"; String result = instance.removePiece(move, currentMovingPiece); assertEquals("1", "e2-e4", result); move = "e4"; currentMovingPiece = "pawn"; result = instance.removePiece(move, currentMovingPiece); assertEquals("2", "e4", result); move = "Q2xe4"; currentMovingPiece = "queen"; result = instance.removePiece(move, currentMovingPiece); assertEquals("3", "2xe4", result); } public void testRemoveEndSquare() { System.out.println("removeEndSquare"); Move instance = new Move(11, "e2!", "Q4xe7+!?"); // some dummy instance String move = "e2-e4"; String result = instance.removeEndSquare(move); assertEquals("1", "e2-", result); move = "e4"; result = instance.removeEndSquare(move); assertEquals("2", "", result); move = "ef4"; result = instance.removeEndSquare(move); assertEquals("3", "e", result); } public void testRemoveActionSquare() { System.out.println("removeActionSquare"); Move instance = new Move(11, "e2!", "Q4xe7+!?"); // some dummy instance // moveWithoutEndSquare String move = "e2-"; String result = instance.removeActionSquare(move); assertEquals("1", "e2", result); move = ""; result = instance.removeActionSquare(move); assertEquals("2", "", result); move = "ex"; result = instance.removeActionSquare(move); assertEquals("3", "e", result); } }