forked from kvesteri/python-poker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
138 lines (109 loc) · 4.04 KB
/
tests.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
from pytest import raises
from pokerbot import Card, Deal, Hand, Table, Player, Range
from pokerbot.hand_eval import Two
class TestCard(object):
def test_rank(self):
card = Card(9, 1)
assert card.rank == 9
class TestTwoCardEval(object):
def test_evaluate_rank(self):
assert Two.evaluate_rank([Card(14, 1), Card(13, 2)]) == 12
assert Two.evaluate_rank([Card(14, 1), Card(13, 1)]) == 8
#print len(range_.hands)
def test_evaluate_percentile(self):
assert Two.evaluate_percentile([Card(14, 1), Card(14, 2)]) == 1
assert Two.evaluate_percentile([Card(14, 1), Card(14, 2)]) == 1
class TestRange(object):
def test_top_5_percent_range_as_string(self):
range_ = Range.top(0.05)
assert str(range_) == '77+, AJs+, AKo+'
def test_top_10_percent_range_as_string(self):
range_ = Range.top(0.10)
assert str(range_) == '66+, A8s+, ATo+'
def test_top_20_percent_range_as_string(self):
range_ = Range.top(0.20)
assert str(range_) == '55+, A3s+, K9o+'
def test_top_30_percent_range_as_string(self):
range_ = Range.top(0.30)
assert str(range_) == '44+, J9s+, Q9o+'
def test_top_40_percent_range_as_string(self):
range_ = Range.top(0.40)
assert str(range_) == '33+, T8s+, K4o+'
def test_top_50_percent_range_as_string(self):
range_ = Range.top(0.50)
assert str(range_) == '22+, J5s+, T8o+'
def test_paired_range_from_string(self):
range_ = Range.from_str('66+')
assert str(range_) == '66+'
def test_suited_range_from_string(self):
range_ = Range.from_str('79s+')
assert str(range_) == '97s+'
def test_supports_length(self):
range_ = Range.from_str('97s+')
assert len(range_) == 176
def test_all_hands(self):
range_ = Range.top(1)
assert len(range_) == 1326
def test_range_of_AA(self):
range_ = Range.from_str('AA')
assert len(range_) == 6
def test_bottom_10_percent_range_as_string(self):
range_ = Range.bottom(0.1)
class TestTable(object):
# def test_new_deal_fails_if_no_players_present(self):
# with raises(Exception):
# table = Table()
# table.new_deal()
# def test_new_deal_fails_if_only_player_present(self):
# with raises(Exception):
# table = Table()
# table.add_player(Player(name=u'Baller'), 100)
# table.new_deal()
def test_new_deal(self):
table = Table()
table.add_player(Player(name=u'Marjo'), 100)
table.add_player(Player(name=u'Konsta'), 100)
deal = table.new_deal()
deal.deal_preflop({
'Konsta': [Card('Ad'), Card('Kd')],
'Marjo': [Card('As'), Card('5c')]
})
print "--- GAME BEGINS ---"
for name, hand in deal.starting_hands.items():
print name, str(hand)
deal.deal_flop([Card('6s'), Card('7s'), Card('Ks')])
deal.deal_turn([Card('Kc')])
deal.deal_river([Card('2s')])
print 'Final board :', deal.board
hand1 = deal.get_hand('Konsta')
hand2 = deal.get_hand('Marjo')
print 'Marjon käsi :', hand2, hand2.score
print 'Konsta käsi :', hand1, hand1.score
print "Winner is: %s" % deal.winner.name
# class TestHand(object):
# def test_hand_list_sorting(self):
# list_of_hands = [
# Hand([
# Card(2, 'c'),
# Card(3, 'c'),
# Card(8, 'd'),
# Card(8, 'c'),
# Card(10, 's')
# ]),
# Hand([
# Card(2, 's'),
# Card(3, 's'),
# Card(4, 's'),
# Card(5, 's'),
# Card(6, 's')
# ]),
# Hand([
# Card(2, 's'),
# Card(3, 'c'),
# Card(4, 's'),
# Card(5, 's'),
# Card(6, 's')
# ])
# ]
# list_of_hands.sort()
# #print list_of_hands