Skip to content

Commit

Permalink
Passed testGetPieceAbbreviation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kestutis-Z committed Nov 7, 2012
1 parent 76dac42 commit 1de79bb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions endgame-oracle/src/main/java/chess/Piece.java
Expand Up @@ -54,4 +54,15 @@ public PieceColour getPieceColour() {
return pieceColour;
}

/** @return short form of this piece's name */
public String getPieceAbbreviation() {
String pieceAbbreviation = "";
pieceAbbreviation += this.pieceColour.getPieceColourAbbreviation();
pieceAbbreviation += this.pieceType.getPieceTypeAbbreviation();
char lastCharOfName = this.name().charAt(this.name().length() - 1);
if (Character.isDigit(lastCharOfName))
pieceAbbreviation += lastCharOfName;
return pieceAbbreviation;
}

}
30 changes: 30 additions & 0 deletions endgame-oracle/src/test/java/chess/PieceTest.java
@@ -0,0 +1,30 @@
package chess;

import static org.junit.Assert.*;

import org.junit.Test;

public class PieceTest {

@Test
public void testGetPieceAbbreviation() {
Piece pc1 = Piece.BLACK_BISHOP_2;
String expectedAbbreviation = "BB2";
String actualAbbreviation = pc1.getPieceAbbreviation();

assertEquals(expectedAbbreviation, actualAbbreviation);

Piece pc2 = Piece.WHITE_KNIGHT;
expectedAbbreviation = "WN";
actualAbbreviation = pc2.getPieceAbbreviation();

assertEquals(expectedAbbreviation, actualAbbreviation);

Piece pc3 = Piece.WHITE_PAWN_3;
expectedAbbreviation = "WP3";
actualAbbreviation = pc3.getPieceAbbreviation();

assertEquals(expectedAbbreviation, actualAbbreviation);
}

}
Binary file modified endgame-oracle/target/classes/chess/Piece.class
Binary file not shown.
Binary file not shown.

0 comments on commit 1de79bb

Please sign in to comment.