Permalink
Browse files

Passed testGetPieceAbbreviation

  • Loading branch information...
1 parent 76dac42 commit 1de79bbfd96fd5d7e13434183b3ac50caad5cb9c Kestutis-Z committed Nov 7, 2012
@@ -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;
+ }
+
}
@@ -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 not shown.
Binary file not shown.

0 comments on commit 1de79bb

Please sign in to comment.