-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_yahtzee.py
85 lines (68 loc) · 2.29 KB
/
test_yahtzee.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
import unittest
from hand import Hand
from rules import Rules
class HandTestCase(unittest.TestCase):
def test_hand_number_of_dice(self):
hand = Hand(15, 6)
self.assertEqual(len(hand.hand), 15)
def test_hand_sides_per_die(self):
hand = Hand(5, 18)
for i in hand.hand:
self.assertEqual(i.sides, 18)
class RulesTestCase(unittest.TestCase):
def test_aces(self):
hand = Hand()
for i in hand.hand:
i._Die__face = 1
self.assertEqual(Rules().aces(hand), 5)
def test_three_of_a_kind(self):
hand = Hand()
for i in range(3):
hand.hand[i]._Die__face = 1
for i in range(3, 5):
hand.hand[i]._Die__face = 2
self.assertEqual(Rules().three_of_a_kind(hand), 7)
def test_four_of_a_kind(self):
hand = Hand()
for i in range(4):
hand.hand[i]._Die__face = 1
for i in range(4, 5):
hand.hand[i]._Die__face = 2
self.assertEqual(Rules().four_of_a_kind(hand), 6)
def test_full_house(self):
hand = Hand()
for i in range(1):
hand.hand[i]._Die__face = 2
for i in range(1, 3):
hand.hand[i]._Die__face = 2
for i in range(3, 5):
hand.hand[i]._Die__face = 3
self.assertEqual(Rules().full_house(hand), 25)
def test_small_straight(self):
hand = Hand()
hand.hand[0]._Die__face = 4
hand.hand[1]._Die__face = 3
hand.hand[2]._Die__face = 5
hand.hand[3]._Die__face = 2
hand.hand[4]._Die__face = 5
self.assertEqual(Rules().small_straight(hand), 30)
def test_large_straight(self):
hand = Hand()
hand.hand[0]._Die__face = 4
hand.hand[1]._Die__face = 3
hand.hand[2]._Die__face = 5
hand.hand[3]._Die__face = 2
hand.hand[4]._Die__face = 1
self.assertEqual(Rules().large_straight(hand), 40)
def test_yahtzee(self):
hand = Hand()
for i in hand.hand:
i._Die__face = 3
self.assertEqual(Rules().yahtzee(hand), 50)
def test_chance(self):
hand = Hand()
for i in range(5):
hand.hand[i]._Die__face = i + 1
self.assertEqual(Rules().chance(hand), 15)
if __name__ == '__main__':
unittest.main()