-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.spec.js
110 lines (85 loc) · 2.52 KB
/
game.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* globals Game */
var sinon = require('sinon');
require('mocha-sinon');
require('./game.js');
describe('The test environment', function() {
it('should pass', function() {
expect(true).toBe(true);
});
it('should access game', function() {
expect(Game).toBeDefined();
});
});
describe('Game Play', function() {
beforeEach(function() {
this.sinon.stub(console, 'log');
});
afterEach(function () {
console.log.restore(); // Unwraps the spy
});
// Testing: add
function addPlayers(n) {
var output = [];
var game = new Game();
for (var i = 1; i < n + 1; i ++){
var playerName = 'player' + i;
var playerAddedStr = playerName + ' was added';
var playerNoStr = 'They are player number ' + i;
output.push([playerAddedStr]);
output.push([playerNoStr]);
game.add(playerName);
}
expect( console.log.callCount ).toBe(n * 2);
expect(console.log.args.join()).toBe(output.join());
}
it('Should add one new Player', function(){
addPlayers(1);
});
it('Should add 10 new Players', function(){
addPlayers(10);
});
// Testing: isPlayable
it('Should be playable after adding two players', function(){
var game = new Game();
game.add('Anas');
game.add('Tom');
expect(game.isPlayable(game.howManyPlayers())).toBe(true);
});
it('Should not be playable after adding one player', function(){
var game = new Game();
game.add('Tom');
expect(game.isPlayable(game.howManyPlayers())).toBe(false);
});
it('Should not be playable after adding one player, testing with no input to is playable', function(){
var game = new Game();
game.add('Tom');
expect(game.isPlayable()).toBe(false);
});
// Testing: roll
it('Should be able to roll the dice', function(){
var game = new Game();
var dice = 3;
var expectedOutput = [ [ 'Tom was added' ],
[ 'They are player number 1' ],
[ 'Dan was added' ],
[ 'They are player number 2' ],
[ 'Tom is the current player' ],
[ 'They have rolled a ' + dice ],
[ 'Tom\'s new location is ' + dice ],
[ 'The category is Rock' ],
[ 'Rock Question 0' ] ];
game.add('Tom');
game.add('Dan');
game.roll(dice);
expect(console.log.args.join()).toBe(expectedOutput.join());
});
// Should be able to play
it('Should be able to play', function(){
var game = new Game();
var dice = 5;
var randNo = 7;
var playersNo = 4;
game.play(playersNo, dice, randNo);
expect(console.log.args.join().length).toBe(3851);
});
});