1
|
|
|
var assert = require('assert'); |
2
|
|
|
const game = require("../../src/chess/Game"); |
3
|
|
|
|
4
|
|
|
describe('Game module', function() { |
5
|
|
|
describe('init the game', function() { |
6
|
|
|
it("should have pieces on the board", function() { |
7
|
|
|
game.init(); |
8
|
|
|
assert.equal(game.p1.color, "white"); |
9
|
|
|
assert.equal(game.p2.color, "black"); |
10
|
|
|
assert.equal(game.p2.color, "black"); |
11
|
|
|
|
12
|
|
|
let square = game.board.getSquare("B", 1); |
13
|
|
|
let pawn = game.p1.pawns[0]; |
14
|
|
|
|
15
|
|
|
assert.equal(square, pawn); |
16
|
|
|
}); |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
it("player should have all pieces", function() { |
20
|
|
|
game.init(); |
21
|
|
|
assert.equal(game.p1.pawns.length, 8); |
22
|
|
|
assert.equal(game.p2.bishops.length, 2); |
23
|
|
|
}); |
24
|
|
|
|
25
|
|
|
it("Row return true if open false if closed", function() { |
26
|
|
|
// B2 to F2 open |
27
|
|
|
assert.equal(game.board.checkRow("B", 2, "F", 2), true) |
28
|
|
|
|
29
|
|
|
// B2 to B5 Closed |
30
|
|
|
assert.equal(game.board.checkRow("B", 5, "B", 2), false) |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
it("Diagonal return true if open false if closed", function() { |
35
|
|
|
assert.equal(game.board.checkDiagonal("B", 2, "D", 4), true) |
36
|
|
|
|
37
|
|
|
assert.equal(game.board.checkDiagonal("A", 1, "C", 3), false) |
38
|
|
|
}); |
39
|
|
|
}); |
40
|
|
|
}); |
41
|
|
|
|