Commit 55a4bb0a authored by Gerson Sunyé's avatar Gerson Sunyé
Browse files

More test guidelines and comments

parent 9382c61e
...@@ -2,21 +2,69 @@ import * as isPossible from '../src/move-validation' ...@@ -2,21 +2,69 @@ import * as isPossible from '../src/move-validation'
import * as pieces from '../src/piece' import * as pieces from '../src/piece'
import { Chessboard, createEmptyChessboard, putPiece } from '../src/chessboard'; import { Chessboard, createEmptyChessboard, putPiece } from '../src/chessboard';
import { Position, position } from '../src/position'; import { Position, position } from '../src/position';
import { Move } from '../src/movements'; import { Move, move } from '../src/movements';
let chessboard : Chessboard; let chessboard : Chessboard;
let positionA4 : Position = position(0, 3) // A4
let positionA5 : Position = position(0, 4) // A5 const positionA4 : Position = position(0, 3) // A4
let positionA6 : Position = position(0, 5) // A6 const positionA5 : Position = position(0, 4) // A5
let positionA7 : Position = position(0, 6) // A7 const positionA6 : Position = position(0, 5) // A6
let positionA8 : Position = position(0, 7) // A8 const positionA7 : Position = position(0, 6) // A7
let positionB6 : Position = position(1, 5) // B6 const positionA8 : Position = position(0, 7) // A8
let positionC6 : Position = position(2, 5) // C6
let positionC4 : Position = position(2, 3) // C4 const positionB1 : Position = position(1, 0) // B1
let positionD2 : Position = position(3, 1) // D2 const positionB2 : Position = position(1, 1) // B2
let positionD3 : Position = position(3, 2) // D3 const positionB6 : Position = position(1, 5) // B6
let positionD4 : Position = position(3, 3) // D4
let positionD5 : Position = position(3, 4) // D5 const positionC3 : Position = position(2, 1) // C3
const positionC4 : Position = position(2, 3) // C4
const positionC5 : Position = position(2, 4) // C5
const positionC6 : Position = position(2, 5) // C6
const positionC7 : Position = position(2, 6) // C7
const positionD2 : Position = position(3, 1) // D2
const positionD3 : Position = position(3, 2) // D3
const positionD4 : Position = position(3, 3) // D4
const positionD5 : Position = position(3, 4) // D5
const positionD6 : Position = position(3, 5) // D6
const positionE1 : Position = position(4, 0) // E1
const positionE4 : Position = position(4, 3) // E4
const positionE8 : Position = position(4, 7) // E8
const positionF2 : Position = position(5, 1) // F2
const positionF6 : Position = position(5, 5) // F6
const positionG3 : Position = position(6, 2) // G3
const positionG5 : Position = position(6, 4) // G5
const positionH1 : Position = position(7, 0) // H1
const positionH4 : Position = position(7, 3) // H4
const positionH7 : Position = position(7, 8) // H7
// Horizontal moves
const moveE4_H4 : Move = move(positionE4, positionH4);
const moveE4_A4 : Move = move(positionE4, positionA4);
// Vertical moves
const moveE4_E1 : Move = move(positionE4, positionE1);
const moveE4_E8 : Move = move(positionE4, positionE8);
// Diagonal moves
const moveE4_A8 : Move = move(positionE4, positionA8);
const moveE4_B1 : Move = move(positionE4, positionB1);
const moveE4_H7 : Move = move(positionE4, positionH7);
const moveE4_H1 : Move = move(positionE4, positionH1);
// Knight moves
const moveE4_F6 : Move = move(positionE4, positionF6);
const moveE4_G5 : Move = move(positionE4, positionG5);
const moveE4_F2 : Move = move(positionE4, positionF2);
const moveE4_G3 : Move = move(positionE4, positionG3);
const moveE4_D2 : Move = move(positionE4, positionD2);
const moveE4_C3 : Move = move(positionE4, positionC3);
const moveE4_C5 : Move = move(positionE4, positionC5);
const moveE4_D6 : Move = move(positionE4, positionD6);
// Impossible moves
const moveE4_C7 : Move = move(positionE4, positionC7);
const moveE4_B2 : Move = move(positionE4, positionB2);
describe("Test blackPawnMove()", () => { describe("Test blackPawnMove()", () => {
beforeEach( () => { beforeEach( () => {
...@@ -145,26 +193,23 @@ describe("Test kingMove()", () => { ...@@ -145,26 +193,23 @@ describe("Test kingMove()", () => {
beforeEach( () => { beforeEach( () => {
// TODO: // TODO:
// Initialize an empty chessboard // Initialize an empty chessboard
// Place a black King on E4
}); });
it("A King can move 1 square in all directions", () => { it("A King can move 1 square in all directions", () => {
// Place a black King on E4 at the empty chessboard
// Check it can move to squares D3, D4, D5, E3, E5, F3, F4, and F5 // Check it can move to squares D3, D4, D5, E3, E5, F3, F4, and F5
}) })
it("A King cannot move more than 1 square", () => { it("A King cannot move more than 1 square", () => {
// Place a black King on E4 at the empty chessboard
// Check it cannot move to squares C2, C3, C4, C6, D4, and F4 // Check it cannot move to squares C2, C3, C4, C6, D4, and F4
}) })
it("A King cannot capure pieces from the same color", () => { it("A King cannot capure pieces from the same color", () => {
// Place a black King on E4 at the empty chessboard
// Place a black Pawn on E5 // Place a black Pawn on E5
// Check the King cannot move to E5. // Check the King cannot move to E5.
}) })
it("A King can capure pieces from a different color", () => { it("A King can capure pieces from a different color", () => {
// Place a black King on E4 at the empty chessboard
// Place a white Pawn on E5 // Place a white Pawn on E5
// Check the King can move to E5. // Check the King can move to E5.
}) })
...@@ -177,22 +222,46 @@ describe("Test queenMove()", () => { ...@@ -177,22 +222,46 @@ describe("Test queenMove()", () => {
beforeEach( () => { beforeEach( () => {
// TODO: // TODO:
// Initialize an empty chessboard // Initialize an empty chessboard
// Place a white Queen on E4
});
it("A Queen can move diagonally", () => {
// TODO:
// Check the following moves are possible:
// moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1
}); });
it("A Queen can move several squares in any direction", () => { it("A Queen can move horizontally", () => {
// TODO: // TODO:
// Check the following moves are possible: moveE4_H4, moveE4_A4
}); });
it("A Queen can move vertically", () => {
// TODO:
// Check the following moves are possible: moveE4_E1, moveE4_E8
});
it("A Queen can only move horizontally, vertically, and diagonally", () => { it("A Queen can only move horizontally, vertically, and diagonally", () => {
// TODO: // TODO:
// Check the following moves are impossible: moveE4_C7, moveE4_B2
}); });
it("A Queen cannot move when there are other pieces between the initial and final squares", () => {
// TODO: it("A Queen cannot leap other pieces", () => {
// TODO:
// Place a white Pawn on C6 and a black Pawn on F4
// Check the moves moveE4_A8 and moveE4_H4 are impossible
}); });
it("A Queen cannot capure pieces from the same color", () => { it("A Queen cannot capure pieces from the same color", () => {
// TODO: // TODO:
// Place a white Pawn on H4
// Check the move moveE4_H4 is impossible
}); });
it("A Queen can capure pieces from a different color", () => { it("A Queen can capure pieces from a different color", () => {
// TODO: // TODO:
// Place a black Pawn on H4
// Check the move moveE4_H4 is possible
}); });
}); });
...@@ -203,24 +272,42 @@ describe("Test bishopMove()", () => { ...@@ -203,24 +272,42 @@ describe("Test bishopMove()", () => {
beforeEach( () => { beforeEach( () => {
// TODO: // TODO:
// Initialize an empty chessboard // Initialize an empty chessboard
// Place a black Bishop on E4
}); });
it("A Bishop can move diagonally", () => { it("A Bishop can move diagonally", () => {
// TODO: // TODO:
// Check the following moves are possible:
// moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1
}); });
it("A Bishop cannot move horizontally", () => { it("A Bishop cannot move horizontally", () => {
// TODO: // TODO:
// Check the following moves are impossible: moveE4_H4, moveE4_A4
}); });
it("A Bishop cannot move vertically", () => { it("A Bishop cannot move vertically", () => {
// TODO: // TODO:
// Check the following moves are impossible: moveE4_E1, moveE4_E8
}); });
it("A Bishop can capture a piece from another color", () => { it("A Bishop can capture a piece from another color", () => {
// TODO: // TODO:
// Place a white Pawn on A8
// Check the move moveE4_A8 is possible
}); });
it("A Bishop cannot capture a piece from the same color", () => { it("A Bishop cannot capture a piece from the same color", () => {
// TODO: // TODO:
// Place a black Pawn on A8
// Check the move moveE4_A8 is impossible
}); });
it("A Bishop cannot move when there are other pieces between the initial and final squares", () => {
it("A Bishop cannot leap other pieces", () => {
// TODO: // TODO:
// Place a white Pawn on C6
// Check the move moveE4_A8 is impossible
}); });
}); });
...@@ -265,38 +352,41 @@ describe("Test roockMove()", () => { ...@@ -265,38 +352,41 @@ describe("Test roockMove()", () => {
beforeEach( () => { beforeEach( () => {
// TODO: // TODO:
// Initialize an empty chessboard // Initialize an empty chessboard
// Place a white Rook on E4
}); });
it("A roock can move horizontally", () => { it("A roock can move horizontally", () => {
// TODO: // TODO:
// Place a roock in E4 in the empty board // Check the following moves are possible: moveE4_H4, moveE4_A4
// Check the roock can move to H4
// Check the roock can mobe to A4
}); });
it("A roock can move vertically", () => { it("A roock can move vertically", () => {
// TODO: // TODO:
// Place a roock in E4 in the empty board // Check the following moves are possible: moveE4_E1, moveE4_E8
// Check the roock can move to E1
// Check the roock can mobe to E8
}); });
it("A roock cannot move diagonally", () => { it("A roock cannot move diagonally", () => {
// TODO: // TODO:
// Place a roock in E4 in the empty board // Check the following moves are impossible:
// Check the roock cannot move to A8 // moveE4_A8, moveE4_B1, moveE4_H7, moveE4_H1
// Check the roock cannot mobe to H7
}); });
it("A roock can capture a piece from another color", () => { it("A roock can capture a piece from another color", () => {
// TODO: // TODO:
// Place a black Pawn on H4
// Check the move moveE4_H4 is possible
}); });
it("A roock cannot capture a piece from the same color", () => { it("A roock cannot capture a piece from the same color", () => {
// TODO: // TODO:
// Place a white Pawn on H4
// Check the move moveE4_H4 is impossible
}); });
it("A Roock cannot move when there are other pieces between the initial and final squares", () => { it("A Roock cannot leap other pieces", () => {
// TODO: // TODO:
// Place a black Pawn on F4
// Check the move moveE4_H4 is impossible
}); });
}); });
\ No newline at end of file
...@@ -12,6 +12,18 @@ export interface Move { ...@@ -12,6 +12,18 @@ export interface Move {
to? : Position; to? : Position;
} }
/**
* Creates a new Move from two Positions, representing
* the Move's initial and final position.
*
* @param from The initial position
* @param to The final position
*/
export function move(from: Position, to: Position): Move {
let move: Move = {from: from, to: to, isValid: true};
return move;
}
/** /**
* Processes a move received from a client browser. * Processes a move received from a client browser.
* If the move is valid and possible, the move is performed and this function * If the move is valid and possible, the move is performed and this function
......
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