This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
test_tictactoe.py
62 lines (45 loc) · 1.89 KB
/
test_tictactoe.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
import unittest
from unittest.mock import patch
import tictactoe
from tictactoe import *
class TestGameSetup(unittest.TestCase):
def test_new_game(self):
self.assertEqual(new_game(),"EEEEEEEEE")
def test_get_starting_player(self):
self.assertIsInstance(get_starting_player(), bool)
class TestGamePlay(unittest.TestCase):
def test_humans_move_01(self):
game = "EEEEEEEEE"
expected = "EEXEEEEEE"
# patch the input function to always return '2'
with patch.object(tictactoe, "input", create=True,
return_value='2'):
self.assertEqual(humans_move(game), expected)
def test_humans_move_02(self):
game = "EEEEEEEEE"
expected = "EEEEEEEXE"
# patch the input function to always return '7'
with patch.object(tictactoe, "input", create=True, return_value='7'):
self.assertEqual(humans_move(game), expected)
def test_computers_move(self):
self.assertEqual(computers_move("EOEXXEEEE"),"OOEXXEEEE")
def test_computer_move_1(self):
self.assertEqual(computers_move("XOOEXXEXE"),"XOOOXXEXE")
def test_computer_move_2(self):
self.assertEqual(computers_move("XOOXXXOXE"),"XOOXXXOXO")
def test_human_wins(self):
self.assertEqual(check_winner('XXXEOEEOO'), 'Human Wins!')
def test_computer_wins(self):
self.assertEqual(check_winner('EEOXEOXXO'), 'Computer Wins!')
def test_draw(self):
self.assertEqual(check_winner('XOXOXOOXO'), 'Draw!')
def test_none(self):
self.assertEqual(check_winner('EEEEEOXEX'), None)
def test_print_1(self):
game = "EEEEEEEEE"
self.assertEqual(print_board(game),"EEE\nEEE\nEEE")
def test_print_2(self):
game = "EXEEOEXEE"
self.assertEqual(print_board(game),"EXE\nEOE\nXEE")
if __name__ == '__main__':
unittest.main()