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
|
|
|
|
11
|
|
|
let square = game.board.getSquare("B", 1).piece; |
12
|
|
|
let pawn = game.p1.pawns[0]; |
13
|
|
|
|
14
|
|
|
assert.equal(square, pawn); |
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
it("player should have all pieces", function() { |
19
|
|
|
game.init(); |
20
|
|
|
assert.equal(game.p1.pawns.length, 8); |
21
|
|
|
assert.equal(game.p2.bishops.length, 2); |
22
|
|
|
}); |
23
|
|
|
|
24
|
|
|
it("Row return true if open false if closed", function() { |
25
|
|
|
// B2 to F2 open |
26
|
|
|
assert.equal(game.board.checkRow("B", 2, "F", 2), true) |
27
|
|
|
|
28
|
|
|
// B2 to B5 Closed |
29
|
|
|
assert.equal(game.board.checkRow("B", 5, "B", 2), false) |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
it("Diagonal return true if open false if closed", function() { |
34
|
|
|
assert.equal(game.board.checkDiagonal("B", 2, "D", 4), true) |
35
|
|
|
|
36
|
|
|
assert.equal(game.board.checkDiagonal("A", 1, "C", 3), false) |
37
|
|
|
}); |
38
|
|
|
}); |
39
|
|
|
}); |
40
|
|
|
|