-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_uber.py
57 lines (45 loc) · 1.84 KB
/
test_uber.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
import unittest
import itertools
import ttt
from ttt import GameStates
"""
give assingment
after 15 minutes pause, discussion time
* how many possible game states (9!)
* what possible states can board be in
* introduce GameStates
* groups must pull and merge
give another 15 minutes
"""
def all_boards():
for a in itertools.product('xo.', repeat=3):
for b in itertools.product('xo.', repeat=3):
for c in itertools.product('xo.', repeat=3):
yield a + b + c
class UberTestTTT(unittest.TestCase):
def test_bad_boards(self):
# or something
self.assertEqual(GameStates.invalid, ttt.game_state(None))
self.assertEqual(GameStates.invalid, ttt.game_state("xo.ox.ox."))
self.assertEqual(GameStates.invalid, ttt.game_state([]))
self.assertEqual(GameStates.invalid, ttt.game_state(['.']*8))
self.assertEqual(GameStates.invalid, ttt.game_state(['.']*10))
self.assertEqual(GameStates.invalid, ttt.game_state(['x']*2 + ['.']*7))
self.assertEqual(GameStates.invalid, ttt.game_state(['o']*2 + ['.']*7))
# x goes first
self.assertEqual(GameStates.invalid, ttt.game_state(['o']*1 + ['.']*8))
def _test_all_perms(self):
results = {}
for board in all_boards():
# if board == list("xoxxoxoxo"):
# print board
e = ttt.game_state(list(board))
results[e] = results.get(e, 0) + 1
# {0: 13815, 2: 920, 1: 4520, 3: 412, 4: 16}
print results
self.assertEqual(3**9, sum(results.values()))
self.assertEqual(13815, results[GameStates.invalid])
self.assertEqual(4520, results[GameStates.unfinished])
self.assertEqual(920, results[GameStates.x_wins])
self.assertEqual(412, results[GameStates.o_wins])
self.assertEqual(16, results[GameStates.draw])