Skip to content

Instantly share code, notes, and snippets.

@thieux
Last active August 20, 2018 21:42
Show Gist options
  • Save thieux/4dfbfebe2dff3a34b437f86c5f094f85 to your computer and use it in GitHub Desktop.
Save thieux/4dfbfebe2dff3a34b437f86c5f094f85 to your computer and use it in GitHub Desktop.
function isValidMove(turn, piece, startSquare, endSquare) {
const startFile = startSquare[0];
const endFile = endSquare[0];
const startRank = startSquare[1];
const endRank = endSquare[1];
if (endRank - startRank > 1) {
return false;
}
return startFile === endFile;
}
describe('Correct pawn moves for whites', function () {
it('should be valid guess when same file and one rank ahead', function () {
expect(isValidMove('WHITES', 'PAWN', 'e2', 'e3')).toEqual(true);
});
it('should be an error when same file but three rank ahead', function () {
expect(isValidMove('WHITES', 'PAWN', 'e2', 'e5')).toEqual(false);
});
it('should be an error to be on a different file', function () {
expect(isValidMove('WHITES', 'PAWN', 'e2', 'd2')).toEqual(false);
});
it('should be an error to be on a different file', function () {
expect(isValidMove('WHITES', 'PAWN', 'e2', 'c2')).toEqual(false);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment