Skip to content

Commit

Permalink
Replaced else statement with check for type Move
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Lapinski committed Jul 4, 2017
1 parent 8fc3707 commit cb67b60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions models/board.js
Expand Up @@ -73,6 +73,10 @@ class Board {
}

applyMove(move) {
if( !(move instanceof Move) ) {
throw new Error('move must be an instanceof Move');
}

if(this.getTile(move.x, move.y) !== Game.EmptyCell) {
throw new Error('cell must be empty to apply move');
}
Expand All @@ -84,9 +88,6 @@ class Board {
else if( move.player === Game.PlayerO) {
nextPlayer = Game.PlayerX;
}
else {
throw new Error(`Unknown Player ${move.player}`);
}

if (move.player !== this._currentTurn) {
throw new Error(`The board's current player is ${this._currentTurn} but a move for player `+
Expand Down
8 changes: 8 additions & 0 deletions test/board.js
Expand Up @@ -320,6 +320,14 @@ describe('Board', () => {
});

describe('#applyMove', () => {
it('should throw an error with invalid parameters', () => {
const board = new Board();

expect(() => {
board.applyMove({x:1, y:1, player:1});
}).to.throw(Error, 'Move');
});

it('should apply a valid move to an empty board.', () => {
const board = new Board();
const firstMove = new Move(1, 1, Game.PlayerX);
Expand Down

0 comments on commit cb67b60

Please sign in to comment.