Commit 713df1cc authored by Maxime PERRIN's avatar Maxime PERRIN
Browse files

test bishop

parent 00da295a
......@@ -331,42 +331,84 @@ describe("Test bishopMove()", () => {
beforeEach( () => {
// TODO:
// Initialize an empty chessboard
chessboard = createEmptyChessboard();
// Place a black Bishop on E4
putPiece(chessboard, positionE4, pieces.blackBishop);
});
it("A Bishop can move diagonally", () => {
// TODO:
// Check the following moves are possible:
// moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1
let diagonalForwardLeftMove = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.bishopMove(chessboard,diagonalForwardLeftMove )).toBeTruthy();
let diagonalForwardRightMove = {from: positionE4, to: positionH7, isValid: true};
expect(isPossible.bishopMove(chessboard,diagonalForwardRightMove )).toBeTruthy();
let diagonalBackwardLeftMove = {from: positionE4, to: positionB1, isValid: true};
expect(isPossible.bishopMove(chessboard,diagonalBackwardLeftMove )).toBeTruthy();
let diagonalBackwardRightMove = {from: positionE4, to: positionH1, isValid: true};
expect(isPossible.bishopMove(chessboard,diagonalBackwardRightMove )).toBeTruthy();
});
it("A Bishop cannot move horizontally", () => {
// TODO:
// Check the following moves are impossible: moveE4_H4, moveE4_A4
let horizontalRightMove = {from: positionE4, to: positionH4, isValid: true};
expect(isPossible.bishopMove(chessboard,horizontalRightMove )).toBeFalsy();
let horizontalLeftMove = {from: positionE4, to: positionA4, isValid: true};
expect(isPossible.bishopMove(chessboard,horizontalLeftMove )).toBeFalsy();
});
it("A Bishop cannot move vertically", () => {
// TODO:
// Check the following moves are impossible: moveE4_E1, moveE4_E8
let verticalBackwardMove = {from: positionE4, to: positionE1, isValid: true};
expect(isPossible.bishopMove(chessboard,verticalBackwardMove )).toBeFalsy();
let verticalForwardMove = {from: positionE4, to: positionE8, isValid: true};
expect(isPossible.bishopMove(chessboard,verticalForwardMove )).toBeFalsy();
});
it("A Bishop can capture a piece from another color", () => {
// TODO:
// Place a white Pawn on A8
putPiece(chessboard, positionA8, pieces.whitePawn);
// Check the move moveE4_A8 is possible
let canCapture = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.bishopMove(chessboard,canCapture)).toBeTruthy();
});
it("A Bishop cannot capture a piece from the same color", () => {
// TODO:
// Place a black Pawn on A8
putPiece(chessboard, positionA8, pieces.blackPawn);
// Check the move moveE4_A8 is impossible
let cannotCapture = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.bishopMove(chessboard,cannotCapture)).toBeFalsy();
});
it("A Bishop cannot leap other pieces", () => {
// TODO:
// Place a white Pawn on C6
putPiece(chessboard, positionC6, pieces.whitePawn);
// Check the move moveE4_A8 is impossible
let cannotLeap = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.bishopMove(chessboard,cannotLeap)).toBeFalsy();
});
});
......@@ -412,6 +454,7 @@ describe("Test rookMove()", () => {
// TODO:
// Initialize an empty chessboard
chessboard = createEmptyChessboard();
// Place a white Rook on E4
putPiece(chessboard, positionE4, pieces.whiteRoock);
......@@ -420,6 +463,7 @@ describe("Test rookMove()", () => {
it("A roock can move horizontally", () => {
// TODO:
// Check the following moves are possible: moveE4_H4, moveE4_A4
let horizontalRightMove = {from: positionE4, to: positionH4, isValid: true};
expect(isPossible.rookMove(chessboard, horizontalRightMove)).toBeTruthy();
......@@ -430,6 +474,7 @@ describe("Test rookMove()", () => {
it("A roock can move vertically", () => {
// TODO:
// Check the following moves are possible: moveE4_E1, moveE4_E8
let verticalForwardMove = {from: positionE4, to: positionE1, isValid: true};
expect(isPossible.rookMove(chessboard, verticalForwardMove)).toBeTruthy();
......@@ -441,6 +486,7 @@ describe("Test rookMove()", () => {
// TODO:
// Check the following moves are impossible:
// moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1
let diagonalForwardLeftMove = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.rookMove(chessboard, diagonalForwardLeftMove)).toBeFalsy();
......@@ -458,6 +504,7 @@ describe("Test rookMove()", () => {
// TODO:
// Place a black Pawn on H4
putPiece(chessboard, positionH4, pieces.blackPawn);
// Check the move moveE4_H4 is possible
let canCapture: Move = {from: positionE4, to: positionH4, isValid: true}
expect(isPossible.rookMove(chessboard, canCapture)).toBeTruthy();
......@@ -467,6 +514,7 @@ describe("Test rookMove()", () => {
// TODO:
// Place a white Pawn on H4
putPiece(chessboard, positionH4, pieces.whitePawn);
// Check the move moveE4_H4 is impossible
let cannotCapture: Move = {from: positionE4, to: positionH4, isValid: true}
expect(isPossible.rookMove(chessboard, cannotCapture)).toBeFalsy();
......@@ -476,6 +524,7 @@ describe("Test rookMove()", () => {
// TODO:
// Place a black Pawn on F4
putPiece(chessboard, positionF4, pieces.blackPawn);
// Check the move moveE4_H4 is impossible
let cannotCapture: Move = {from: positionE4, to: positionH4, isValid: true}
expect(isPossible.rookMove(chessboard, cannotCapture)).toBeFalsy();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment