This repository has been archived by the owner on Apr 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
108 lines (98 loc) · 2.37 KB
/
tests.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
QUnit.module( "result check" );
QUnit.test("3 x in a row/col/diag", function(assert) {
assert.deepEqual(checkResult({
"count": 3,
"summ": 3
}, 3), {
"gameover": true,
"winner": 1
}, "X won");
});
QUnit.test("3 o in a row/col/diag", function(assert) {
assert.deepEqual(checkResult({
"count": 3,
"summ": 0
}, 3), {
"gameover": true,
"winner": 0
}, "O won");
});
QUnit.test("Game in progress", function(assert) {
assert.deepEqual(checkResult({
"count": 1,
"summ": 0
}, 3), false, "Nothing special");
});
QUnit.module( "someone wins" );
QUnit.test("X wins in a row", function(assert) {
assert.deepEqual(checkBoard([
[1, 1, 1],
[0, 0, 1],
[0, 1, 0]
], 3), {
"gameover": true,
"winner": 1
}, "3 X in first row!");
});
QUnit.test("X wins in a column", function(assert) {
assert.deepEqual(checkBoard([
[1, 0, 0],
[1, 0, 1],
[1, 1, 0]
], 3), {
"gameover": true,
"winner": 1
}, "3 X in first column!");
});
QUnit.test("X wins in a left diag", function(assert) {
assert.deepEqual(checkBoard([
[1, 0, 0],
[0, 1, 0],
[1, 0, 1]
], 3), {
"gameover": true,
"winner": 1
}, "3 x in left giag!");
});
QUnit.test("O wins in a right diag", function(assert) {
assert.deepEqual(checkBoard([
[1, 0, 0],
[1, 0, 0],
[0, 1, 1]
], 3), {
"gameover": true,
"winner": 0
}, "3 o in right diag!");
});
QUnit.module( "5x5" );
QUnit.test("5x5 X wins", function(assert) {
assert.deepEqual(checkBoard([
[1, 1, 1 ,1 ,1],
[0, 0, 1, 0 ,0],
[0, 1, 0, 0 ,0],
[0, 0, 1, 0 ,0],
[0, 1, 0, 0 ,0]
], 5), {
"gameover": true,
"winner": 1
}, "5 X in first row!");
});
QUnit.module( "no winner" );
QUnit.test("game in process", function(assert) {
assert.deepEqual(checkBoard([
[1, 0, 1],
[undefined, undefined, undefined],
[undefined, undefined, undefined]
], 3), {
"gameover": false
}, "Only first row");
});
QUnit.test("Toe", function(assert) {
assert.deepEqual(checkBoard([
[1, 0, 1],
[0, 0, 1],
[1, 1, 0]
], 3), {
"gameover": true
}, "Noone won. Game over");
});