-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectFourTest.py
130 lines (104 loc) · 3.26 KB
/
ConnectFourTest.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import unittest
from user import *
from game import *
class ConnectFourTest(unittest.TestCase):
#
#
# Given: A user "Jessica"
# When : User is transformed into a string
# Then : "Jessica" string is returned
def test_user_Jessica(self):
# Given
jessica = User("Jessica")
# When
toString = str(jessica)
# Then
self.assertEqual("Jessica", toString)
#
#
# Given: A user "Jessica" and a new game
# When : "Jessica" joins the game
# Then : "Jessica" is the sole player in the game
def test_Jessica_joins_a_new_game(self):
# Given
jessica = User("Jessica")
game = Game()
# When
game.accepts(jessica)
# Then
self.assertEqual([jessica], game.players)
#
#
# Given: A user "Robert" and a game with "Jessica"
# When : "Robert" joins the game
# Then : "Jessica" and "Robert" are the both players in the game
def test_Robert_joins_a_game_with_Jessica(self):
# Given
robert = User("Robert")
game = Game()
jessica = User("Jessica")
game.accepts(jessica)
# When
game.accepts(robert)
# Then
self.assertEqual([jessica, robert], game.players)
#
#
# Given: A user "Patricia" and a game with two players
# When : "Patricia" joins the game
# Then : Game throws a TooManyPlayersException and player list stays the
# same
def test_Patricia_joins_a_game_with_two_players(self):
# Given
patricia = User("Patricia")
game = Game()
robert = User("Robert")
jessica = User("Jessica")
game.accepts(jessica)
game.accepts(robert)
# When-Then
with self.assertRaises(TooManyPlayersException):
game.accepts(patricia)
self.assertEqual([jessica, robert], game.players)
#
#
# Play a turn
#
#
#
# Scenario I: First player plays first shot
#
def test_Jessica_plays_first_shot(self):
# Given
game = Game()
jessica = User("Jessica")
robert = User("Robert")
game.accepts(jessica)
game.accepts(robert)
self.assertEqual(jessica, game.currentPlayer)
# When
game.play(jessica, 0)
# Then
self.assertEqual([jessica], game.getColumn(0))
for i in range(1, 6):
self.assertEqual([], game.getColumn(i))
self.assertEqual(robert, game.currentPlayer)
#
# Scenario II: Second player tries to play first shot
#
# def test_Robert_tries_to_play_first_shot(self):
# # Given
# game = Game()
# jessica = User("Jessica")
# robert = User("Robert")
# game.accepts(jessica)
# game.accepts(robert)
# self.assertEqual(jessica, game.currentPlayer)
# # When-Then
# with self.assertRaises(NotPlayerTurnException):
# game.play(robert, 0)
# for i in range(0, 6):
# self.assertEqual([], game.getColumn(i))
# self.assertEqual(jessica, game.currentPlayer)
if __name__=="__main__":
unittest.main()