Commit 549eaca8 authored by Maxime PERRIN's avatar Maxime PERRIN
Browse files

test queen

parent e3821710
......@@ -281,46 +281,96 @@ describe("Test queenMove()", () => {
beforeEach( () => {
// TODO:
// Initialize an empty chessboard
chessboard = createEmptyChessboard();
// Place a white Queen on E4
putPiece(chessboard, positionE4, pieces.whiteQueen);
});
it("A Queen 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.queenMove(chessboard,diagonalForwardLeftMove )).toBeTruthy();
let diagonalForwardRightMove = {from: positionE4, to: positionH7, isValid: true};
expect(isPossible.queenMove(chessboard,diagonalForwardRightMove )).toBeTruthy();
let diagonalBackwardLeftMove = {from: positionE4, to: positionB1, isValid: true};
expect(isPossible.queenMove(chessboard,diagonalBackwardLeftMove )).toBeTruthy();
let diagonalBackwardRightMove = {from: positionE4, to: positionH1, isValid: true};
expect(isPossible.queenMove(chessboard,diagonalBackwardRightMove )).toBeTruthy();
});
it("A Queen can move horizontally", () => {
// TODO:
// Check the following moves are possible: moveE4_H4, moveE4_A4
let horizontalRightMove = {from: positionE4, to: positionH4, isValid: true};
expect(isPossible.queenMove(chessboard, horizontalRightMove)).toBeTruthy();
let horizontalLeftMove = {from: positionE4, to: positionA4, isValid: true};
expect(isPossible.queenMove(chessboard, horizontalLeftMove)).toBeTruthy();
});
it("A Queen can move vertically", () => {
// TODO:
// Check the following moves are possible: moveE4_E1, moveE4_E8
let verticalForwardMove = {from: positionE4, to: positionE1, isValid: true};
expect(isPossible.queenMove(chessboard, verticalForwardMove)).toBeTruthy();
let verticalBackwardMove = {from: positionE4, to: positionE8, isValid: true};
expect(isPossible.queenMove(chessboard, verticalBackwardMove)).toBeTruthy();
});
it("A Queen can only move horizontally, vertically, and diagonally", () => {
// TODO:
// Check the following moves are impossible: moveE4_C7, moveE4_B2
let randomImpossibleMove = {from: positionE4, to: positionC7, isValid: true};
expect(isPossible.queenMove(chessboard, randomImpossibleMove)).toBeFalsy();
let randomImpossiblebisMove = {from: positionE4, to: positionB2, isValid: true};
expect(isPossible.queenMove(chessboard, randomImpossiblebisMove)).toBeFalsy();
});
it("A Queen cannot leap other pieces", () => {
// TODO:
// Place a white Pawn on C6 and a black Pawn on F4
putPiece(chessboard, positionC6, pieces.whitePawn);
putPiece(chessboard, positionF4, pieces.blackPawn);
// Check the moves moveE4_A8 and moveE4_H4 are impossible
let cannotLeapHisColorMove = {from: positionE4, to: positionA8, isValid: true};
expect(isPossible.queenMove(chessboard, cannotLeapHisColorMove)).toBeFalsy();
let cannotLeapOtherColorMove = {from: positionE4, to: positionH4, isValid: true};
expect(isPossible.queenMove(chessboard, cannotLeapOtherColorMove)).toBeFalsy();
});
it("A Queen cannot capure pieces from the same color", () => {
// TODO:
// Place a white Pawn on H4
putPiece(chessboard, positionH4, pieces.whitePawn);
// Check the move moveE4_H4 is impossible
let cannotCapture = {from: positionE4, to: positionH4, isValid: true};
expect(isPossible.queenMove(chessboard, cannotCapture)).toBeFalsy();
});
it("A Queen can capure pieces from a different color", () => {
// TODO:
// Place a black Pawn on H4
putPiece(chessboard, positionH4, pieces.blackPawn);
// Check the move moveE4_H4 is possible
let canCapture = {from: positionE4, to: positionH4, isValid: true};
expect(isPossible.queenMove(chessboard, canCapture)).toBeTruthy();
});
});
......
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