Last active
August 20, 2018 21:42
-
-
Save thieux/4dfbfebe2dff3a34b437f86c5f094f85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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