-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_Player.py
193 lines (145 loc) · 5.25 KB
/
test_Player.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import pytest
from Data.GAME_LOGIC.uno_Const import *
from Data.GAME_LOGIC.uno_Card import Card
from Data.GAME_LOGIC.unoCore import Game
from Data.GAME_LOGIC.uno_Player import Player
from Data.GAME_LOGIC.uno_Const import *
@pytest.fixture
def game():
p1 = Player('', True)
p2 = Player('', False)
g = Game([p1, p2],MODE_NORMAL)
g.ready((100, 50))
return g
def test_drawOneCard(game):
card1 = Card(RED, 1)
card2 = Card(GREEN, 2)
card3 = Card(BLUE, 3)
clist = [card1, card2, card3]
game.deckList.cardList = clist
p1 = Player('', True)
p1.drawOneCard(game)
assert p1.handCardList == [card3]
assert game.deckList.cardList == [card1, card2]
game.deckList.cardList = []
p1 = Player('', True)
p1.drawOneCard(game)
assert p1.handCardList == []
assert game.deckList.cardList == []
def test_draw(game):
# deck 10, open 10에서 7장 뽑음
game.deckList.cardList = [Card(RED, x) for x in range(0, 10)]
game.openCard.cardList = [Card(RED, x) for x in range(0, 10)]
p1 = Player('', True)
p1.draw(game, 7)
assert len(game.deckList.cardList) == 3
assert len(game.openCard.cardList) == 10
assert len(p1.handCardList) == 7
# deck 3, open 10에서 5장 뽑음
p1.draw(game, 5)
assert len(game.deckList.cardList) == 7
assert len(game.openCard.cardList) == 1
assert len(p1.handCardList) == 12
# deck 8, open 0에서 10장 뽑음
p1.draw(game, 10)
assert len(game.deckList.cardList) == 0
assert len(game.openCard.cardList) == 1
assert len(p1.handCardList) == 19
# deck 0, open 0에서 2장 뽑음
p1.draw(game, 2)
assert len(game.deckList.cardList) == 0
assert len(game.openCard.cardList) == 1
assert len(p1.handCardList) == 19
def test_allHand(game):
p1 = Player('', True)
card1 = Card(RED, 1)
card2 = Card(GREEN, 2)
card3 = Card(BLUE, 3)
clist = [card1, card2, card3]
p1.handCardList = clist
assert p1.allHand() == ['red_1', 'green_2', 'blue_3']
def test_delCard():
p1 = Player('', True)
card1 = Card(RED, 1)
card2 = Card(GREEN, 2)
card3 = Card(BLUE, 3)
clist = [card1, card2, card3]
p1.handCardList = clist
p1.delCard(1)
assert p1.handCardList == [card1, card3]
def test_data():
p1 = Player('user', True)
card1 = Card(RED, 1)
card2 = Card(GREEN, 2)
card3 = Card(BLUE, 3)
clist = [card1, card2, card3]
p1.handCardList = clist
assert p1.data()['playerName'] == 'user'
assert p1.data()['isUser'] == True
assert p1.data()['handCardList'] == clist
p2 = Player('bot', False)
card1 = Card(RED, 3)
card2 = Card(GREEN, 2)
card3 = Card(BLUE, 1)
clist = [card1, card2, card3]
p2.handCardList = clist
assert p2.data()['playerName'] == 'bot'
assert p2.data()['isUser'] == False
assert p2.data()['handCardList'] == clist
def test_UnoAndWinnerChecker(game):
p1 = Player('', True)
card1 = Card(RED, 1)
p1.handCardList = [card1]
p1.UnoAndWinnerChecker(game)
assert game.state == UNO
assert game.botCompeteList != []
p2 = Player('', True)
game.state == NORM
p2.UnoAndWinnerChecker(game)
assert game.winner != None
def test_drawOneCardW(game):
selected = [0, 0]
for i in range(500):
game.deckList.cardList = [Card(RED, 1) for x in range(10)]
game.deckList+ [Card(RED, -1, EFFECT_DRAW, 2) for x in range(10)]
game.deckList.shuffle()
p1 = Player('', True)
p1.drawOneCardW(game)
if p1.handCardList[-1].effectCode == EFFECT_DRAW:
selected[0] += 1
else:
selected[1] += 1
rate = selected[0]/(selected[0]+selected[1])
testValue = False
if (rate > 0.5) and (rate < 0.7):
testValue = True
assert testValue == True
## def weighted_draw와 def drawOneCardW에 대한 테스트 코드를 작성할 것
## printCurSta는 단순 프린트 함수이므로 테스트 코드를 작성하지 않아도 됨
## 해당 함수는 test_drawOneCardW에서 나오는 수치를 보기 위해서 만든 함수입니다.
"""
def printRate():
p1 = Player('', True)
p2 = Player('', False)
game = Game([p1, p2],MODE_NORMAL)
game.ready((100, 50))
selected = [0, 0]
for i in range(500):
game.deckList.cardList = [Card(RED, 1) for x in range(10)]
game.deckList+ [Card(RED, -1, EFFECT_DRAW, 2) for x in range(10)]
game.deckList.shuffle()
p1 = Player('', True)
p1.drawOneCardW(game)
if p1.handCardList[-1].effectCode == EFFECT_DRAW:
selected[0] += 1
else:
selected[1] += 1
if (selected[0] > 0) and (selected[1] > 0):
print(i,": ",selected[0]/(selected[0]+selected[1]))
rate = selected[0]/(selected[0]+selected[1])
print(rate)
testValue = False
if (rate > 0.5) and (rate < 0.7):
testValue = True
"""
#printRate()