-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_gameState.py
127 lines (107 loc) · 4.35 KB
/
test_gameState.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
from unittest import TestCase
from Card import Card
from GameState import GameState
class TestGameState(TestCase):
def setUp(self):
self.game_state = GameState(0)
self.game_state.state = GameState.TRICK_END
self.game_state.trumps = Card.SUIT_DIAMONDS
def test_calc_winnner(self):
# No trumps
self.game_state.lead_card = Card(Card.SUIT_HEARTS, Card.ACE)
self.game_state.trick_cards = {
0: Card(Card.SUIT_CLUBS, 10),
1: Card(Card.SUIT_SPADES, Card.KING),
2: Card(Card.SUIT_HEARTS, Card.ACE),
3: Card(Card.SUIT_HEARTS, 9)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 2)
# Right bower
self.game_state.trick_cards = {
0: Card(Card.SUIT_DIAMONDS, Card.JACK),
1: Card(Card.SUIT_SPADES, Card.KING),
2: Card(Card.SUIT_HEARTS, Card.ACE),
3: Card(Card.SUIT_HEARTS, 9)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 0)
# Left Bower winning
self.game_state.trick_cards = {
0: Card(Card.SUIT_HEARTS, Card.JACK),
1: Card(Card.SUIT_SPADES, Card.KING),
2: Card(Card.SUIT_HEARTS, Card.ACE),
3: Card(Card.SUIT_HEARTS, 9)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 0)
# Left Bower losing
self.game_state.trick_cards = {
0: Card(Card.SUIT_HEARTS, Card.JACK),
1: Card(Card.SUIT_SPADES, Card.KING),
2: Card(Card.SUIT_DIAMONDS, Card.JACK),
3: Card(Card.SUIT_HEARTS, 9)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 2)
# One trump no bowers
self.game_state.trick_cards = {
0: Card(Card.SUIT_HEARTS, Card.ACE),
1: Card(Card.SUIT_SPADES, Card.KING),
2: Card(Card.SUIT_DIAMONDS, 10),
3: Card(Card.SUIT_HEARTS, 9)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 2)
# Trump Battle
self.game_state.trick_cards = {
0: Card(Card.SUIT_DIAMONDS, Card.ACE),
1: Card(Card.SUIT_DIAMONDS, Card.KING),
2: Card(Card.SUIT_DIAMONDS, Card.JACK),
3: Card(Card.SUIT_HEARTS, Card.JACK)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 2)
self.game_state.lead_card = Card(Card.SUIT_DIAMONDS, Card.JACK)
# failed test case
self.game_state.trick_cards = {
2: Card(Card.SUIT_DIAMONDS, Card.JACK),
3: Card(Card.SUIT_DIAMONDS, Card.KING),
0: Card(Card.SUIT_CLUBS, Card.ACE),
1: Card(Card.SUIT_HEARTS, Card.KING)
}
self.game_state.trumps = Card.SUIT_HEARTS
winner = self.game_state.calc_winner()
self.assertEqual(winner, 2)
self.game_state.lead_card = Card(Card.SUIT_DIAMONDS, Card.JACK)
self.game_state.trumps = Card.SUIT_DIAMONDS
self.game_state.trick_cards = {
1: Card(Card.SUIT_DIAMONDS, Card.JACK),
2: Card(Card.SUIT_DIAMONDS, 10),
3: Card(Card.SUIT_HEARTS, Card.JACK),
0: Card(Card.SUIT_DIAMONDS, 9)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 1)
self.game_state.lead_card = Card(Card.SUIT_CLUBS, Card.QUEEN)
self.game_state.trumps = Card.SUIT_HEARTS
self.game_state.trick_cards = {
3: Card(Card.SUIT_CLUBS, Card.QUEEN),
0: Card(Card.SUIT_CLUBS, Card.JACK),
1: Card(Card.SUIT_CLUBS, 9),
2: Card(Card.SUIT_CLUBS, 10),
}
res = self.game_state.trick_cards[0].get_total_value(self.game_state.trumps, Card.SUIT_CLUBS)
self.assertEqual(res, 11 + Card.LEAD_BONUS)
winner = self.game_state.calc_winner()
self.assertEqual(winner, 3)
self.game_state.lead_card = Card(Card.SUIT_SPADES, Card.ACE)
self.game_state.trumps = Card.SUIT_HEARTS
self.game_state.trick_cards = {
1: Card(Card.SUIT_SPADES, Card.ACE),
2: Card(Card.SUIT_SPADES, Card.KING),
3: Card(Card.SUIT_SPADES, 9),
0: Card(Card.SUIT_SPADES, Card.JACK)
}
winner = self.game_state.calc_winner()
self.assertEqual(winner, 1)