-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
87 lines (74 loc) · 2.37 KB
/
tests.py
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
import logging
from utils import check_win
from utils import get_logger
from utils import get_score
from utils import no_more_moves
logger = get_logger('Tests')
def test_check_win():
logger.debug('Testing check_win() from minimax.py')
state = [['X', None, None],
['O', 'X', None],
[None, 'O', 'X']]
assert (check_win(state, 'X') == True)
state = [[None, 'X', 'O'],
[None, 'X', None],
[None, 'O', 'X']]
assert (check_win(state, 'X') == False)
state = [['X', 'O', None],
[None, 'X', None],
[None, 'O', 'X']]
assert (check_win(state, 'O') == False)
state = [['O', None, 'X'],
[None, None, 'X'],
[None, 'O', 'X']]
assert (check_win(state, 'X') == True)
state = [['X', 'O', None],
['X', 'O', None],
['X', 'O', 'X']]
assert (check_win(state, 'X') == True)
assert (check_win(state, 'O') == True)
logger.debug('Passed')
def test_is_end_state():
logger.debug('Testing is_end_state()')
state = [[None, 'X', 'O'],
[None, 'X', None],
[None, 'O', 'X']]
assert (no_more_moves(state) == False)
state = [['X', 'X', 'O'],
['O', 'O', 'X'],
['X', 'O', 'X']]
assert (no_more_moves(state) == True)
logger.debug('Passed')
def test_get_score():
logger.debug('Testing get_score()')
state = [['X', 'X', 'O'],
['O', 'O', 'X'],
['X', 'O', 'X']]
assert (get_score(state, True) == 0)
assert (get_score(state, False) == 0)
state = [['X', None, None],
['O', 'X', None],
[None, 'O', 'X']]
assert (get_score(state, True) == 10)
state = [[None, 'X', 'O'],
[None, 'X', None],
[None, 'O', 'X']]
assert (get_score(state, True) == 0)
assert (get_score(state, False) == 0)
state = [['O', None, 'X'],
[None, None, 'X'],
[None, 'O', 'X']]
assert (get_score(state, True) == 10)
assert (get_score(state, False) == 0)
state = [['X', None, 'O'],
[None, None, 'O'],
[None, 'X', 'O']]
assert (get_score(state, True) == 0)
assert (get_score(state, False) == -10)
logger.debug('Passed')
def test_all():
test_check_win()
test_is_end_state()
test_get_score()
if __name__ == '__main__':
test_all()