-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
185 lines (128 loc) · 5.05 KB
/
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
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
from itertools import repeat
from unittest import TestCase, main as unittest_main
from card import Card
from categories import Categories
from hand import Hand
from suits import Suits
def test_equal(label, a, b):
def runTest(self):
return self.assertEqual(a, b)
return type(label, (TestCase,), {'runTest': runTest})
def test_hand_category(values, category):
hand = Hand.values_as_hand(values)
return test_equal('%sTest' % category, hand.best_category, category)
class CategoriesTest(TestCase):
def test_categories(self):
self.assertLess(Categories.OnePair, Categories.StraightFlush)
class FullHouseTest(TestCase):
def setUp(self):
self.cards = {
Card(5, Suits.Clubs),
Card(5, Suits.Spades),
Card(2, Suits.Hearts),
Card(2, Suits.Diamonds),
Card(2, Suits.Spades),
}
self.hand = Hand(self.cards)
def test_category(self):
self.assertEqual(
self.hand.best_category, Categories.FullHouse, self.hand.count_groups())
def test_kickers(self):
self.assertEqual(self.hand.kickers, set())
def test_punchers(self):
self.assertEqual(self.cards, self.hand.punchers)
class StraightFlushTest(TestCase):
def setUp(self):
self.cards = {Card(v, s) for (v, s) in zip(range(7), repeat(Suits.Spades))}
self.hand = Hand(self.cards)
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.StraightFlush)
def test_kickers(self):
self.assertEqual(self.hand.kickers, set())
def test_punchers(self):
self.assertEqual(self.cards, self.hand.punchers)
class StraightTest(TestCase):
def setUp(self):
self.hand = Hand.values_as_hand([2, 3, 4, 5, 6])
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.Straight)
def test_kickers(self):
self.assertEqual(self.hand.kickers, set())
def test_punchers(self):
self.assertEqual(self.hand.cards, self.hand.punchers)
class FlushTest(TestCase):
def setUp(self):
self.cards = {
Card(1, Suits.Clubs),
Card(2, Suits.Clubs),
Card(5, Suits.Clubs),
Card(6, Suits.Clubs),
Card(7, Suits.Clubs)
}
self.hand = Hand(self.cards)
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.Flush)
def test_kickers(self):
self.assertEqual(self.hand.kickers, set())
def test_punchers(self):
self.assertEqual(self.cards, self.hand.punchers)
# TODO: Change these into ordinary, red-blooded, God-fearing, apple pie-loving unit tests
class FourOfAKind(TestCase):
def setUp(self):
self.hand = Hand.values_as_hand([9, 9, 9, 9, 7])
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.FourOfAKind)
def test_kickers(self):
kicker = self.hand.kickers.pop()
self.assertEqual(kicker.value, 7)
def test_punchers(self):
punchers_values = [c.value for c in self.hand.punchers]
self.assertEqual(punchers_values, [9, 9, 9, 9])
class ThreeOfAKind(TestCase):
def setUp(self):
self.hand = Hand.values_as_hand([1, 1, 1, 4, 5])
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.ThreeOfAKind)
def test_kickers(self):
kickers_values = {c.value for c in self.hand.kickers}
self.assertEqual(kickers_values, {4, 5})
class OnePair(TestCase):
def setUp(self):
self.hand = Hand.values_as_hand([2, 2, 3, 4, 5])
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.OnePair)
def test_kickers(self):
kickers_values = {c.value for c in self.hand.kickers}
self.assertEqual(kickers_values, {3, 4, 5})
class TwoPair(TestCase):
def setUp(self):
self.hand = Hand.values_as_hand([2, 2, 3, 3, 6])
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.TwoPair)
def test_kickers(self):
kicker = self.hand.kickers.pop()
self.assertEqual(kicker.value, 6, kicker)
def test_punchers(self):
pairs_values = {c.value for c in self.hand.punchers}
self.assertEqual(pairs_values, {2, 2, 3, 3})
class HighCardTest(TestCase):
def setUp(self):
self.hand = Hand.values_as_hand([2, 7, 4, 5, 6])
def test_category(self):
self.assertEqual(self.hand.best_category, Categories.HighCard)
def test_kickers(self):
kicker_values = {c.value for c in self.hand.kickers}
self.assertEqual(kicker_values, {2, 4, 5, 6})
def test_punchers(self):
high_card = self.hand.punchers.pop()
self.assertEqual(high_card.value, 7)
class TwoPairVsOnePair(TestCase):
def runTest(self):
one_pair = Hand.values_as_hand([2, 2, 5, 5, 6])
two_pair = Hand.values_as_hand([1, 1, 3, 4, 7])
self.assertGreater(one_pair, two_pair)
class TwoPairVsTwoPair(TestCase):
def runTest(self):
pass
if __name__ == '__main__':
unittest_main()