-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.test.js
102 lines (90 loc) · 2.26 KB
/
game.test.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
'use strict'
:wqimport test from 'ava'
import {generateEmptyGame, config, reduceTurn} from './game.js'
test(t => {
const _ = config.EMPTY_TOKEN
const gameState = generateEmptyGame()
t.deepEqual(gameState.matrix, [[_, _, _], [_, _, _], [_, _, _]])
t.deepEqual(gameState.turn, 0)
})
test(t => {
const X = config.X_TOKEN
const O = config.O_TOKEN
const _ = config.EMPTY_TOKEN
const previousState = {
matrix: [[_, X, _], [_, _, _], [_, _, _]],
turn: 1
}
const action = {
position: [0, 0]
}
const gameState = reduceTurn(previousState, action)
t.deepEqual(gameState.matrix, [[O, X, _], [_, _, _], [_, _, _]])
})
test(t => {
const X = config.X_TOKEN
const _ = config.EMPTY_TOKEN
const previousState = {
matrix: [[_, _, _], [_, _, _], [_, _, _]],
turn: 0
}
const action = {
position: [0, 0]
}
const gameState = reduceTurn(previousState, action)
t.deepEqual(gameState.turn, 1)
})
test(t => {
const X = config.X_TOKEN
const _ = config.EMPTY_TOKEN
const previousState = {
matrix: [[_, _, _], [_, _, _], [_, _, _]],
turn: 0
}
const action = {
position: [0, 0]
}
const gameState = reduceTurn(previousState, action)
t.deepEqual(gameState.matrix, [[X, _, _], [_, _, _], [_, _, _]])
})
test(t => {
const X = config.X_TOKEN
const _ = config.EMPTY_TOKEN
const previousState = {
matrix: [[_, _, _], [_, _, _], [_, _, _]],
turn: 0
}
const action = {
position: [1, 0]
}
const gameState = reduceTurn(previousState, action)
t.deepEqual(gameState.matrix, [[_, X, _], [_, _, _], [_, _, _]])
})
test(t => {
const X = config.X_TOKEN
const O = config.O_TOKEN
const _ = config.EMPTY_TOKEN
const previousState = {
matrix: [[O, _, X], [_, _, _], [_, _, _]],
turn: 2
}
const action = {
position: [1, 0]
}
const gameState = reduceTurn(previousState, action)
t.deepEqual(gameState.matrix, [[O, X, X], [_, _, _], [_, _, _]])
})
test(t => {
const X = config.X_TOKEN
const O = config.O_TOKEN
const _ = config.EMPTY_TOKEN
const previousState = {
matrix: [[X, _, _], [_, _, _], [_, _, _]],
turn: 1
}
const action = {
position: [0, 0]
}
const gameState = reduceTurn(previousState, action)
t.deepEqual(gameState.matrix, [[X, _, _], [_, _, _], [_, _, _]])
})