-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit_test.py
69 lines (61 loc) · 2.27 KB
/
unit_test.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
import unittest
import main
import TicTacToe
import numpy as np
# Creating a class to check unittest
class TestAssertEqual(unittest.TestCase):
def test_func_1(self):
computer_choice = "X"
human_choice = "0"
board_config = np.array([[1,1,0],
[-1,1,1],
[-1,0,0]])
print("Running test for win conditions in the board configuration:")
#Win condition is determined is three move of same kind are in a row, colum or diagonal
testObject = TicTacToe.TicTacToe(board=board_config)
testObject.printGrid(computer_choice, human_choice)
self.assertFalse(testObject.isWinner(user=-1))
print("Test Output: ",testObject.isWinner(user=-1))
#Row winning condition
board_config = np.array([[1,-1,1],
[-1,-1,-1],
[0,-1,0]])
testObject = TicTacToe.TicTacToe(board=board_config)
testObject.printGrid(computer_choice, human_choice)
self.assertTrue(testObject.isWinner(user=-1))
print("Test Output: ",testObject.isWinner(user=-1))
#Column winning condition
board_config = np.array([[1,-1,0],
[1,-1,0],
[1,1,0]])
testObject = TicTacToe.TicTacToe(board=board_config)
testObject.printGrid(computer_choice, human_choice)
self.assertTrue(testObject.isWinner(user=1))
print("Test Output: ",testObject.isWinner(user=1))
#Diagonal winning condition
board_config = np.array([[-1,0,1],
[-1,-1,0],
[0,-1,-1]])
testObject = TicTacToe.TicTacToe(board=board_config)
testObject.printGrid(computer_choice, human_choice)
self.assertTrue(testObject.isWinner(user=-1))
print("Test Output: ",testObject.isWinner(user=-1))
def test_func_2(self):
computer_choice = "X"
human_choice = "0"
board_config = np.array([[1,0,1],
[-1,1,0],
[0,-1,-1]])
print("Running test for minimaxAlgorithm():")
print("Next Turn: Computer (X)")
#Win condition is determined is three move of same kind are in a row, colum or diagonal
testObject = TicTacToe.TicTacToe(board=board_config)
testObject.printGrid(computer_choice, human_choice)
coords = testObject.minimaxAlgorithm(game_depth=4, player=+1)
x, y = coords[0], coords[1]
self.assertEqual((x, y), (0,1))
print("Test Output: ", (x,y))
testObject.updateGrid(x, y, +1)
testObject.printGrid(computer_choice, human_choice)
if __name__ == '__main__':
unittest.main()