-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_card_deck.py
68 lines (53 loc) · 1.79 KB
/
test_card_deck.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
###################################
# Test Module for Class Card and Deck
###################################
'''
The test module build based on the course content of
Michigan State University CSE231 2013 Fall project #8
introduction materials.
'''
from card import Card
from deck import Deck
'''
1. Test Print function on Deck
'''
my_deck = Deck(1, 13, 4)
print("======Basic Sring Representation=====")
print(my_deck)
print("======In Column Format=====")
my_deck.column_print()
my_deck.shuffle()
print("======Shuffled Deck=====")
my_deck.column_print()
'''
2. Test Methods on Card in a poker game context
'''
a_card = my_deck.draw_card()
print("The top card to throw is:",a_card)
print('How many cards left:', len(my_deck))
print("Is this an empty deck?",my_deck.is_empty())
# Simulate a playing context
Dealer_list=[]
Player_list=[]
for i in range(5):
Dealer_list.append(my_deck.draw_card())
Player_list.append(my_deck.draw_card())
print("\nDealer:", Dealer_list)
print("Player:", Player_list)
print()
# take the last card dealt out of each hand
last_card_Dealer = Dealer_list.pop()
last_card_Player = Player_list.pop()
print("Dealer threw down",last_card_Dealer, ", Player threw down", last_card_Player)
print("Hands are now:",Dealer_list, Player_list)
# check the compare functions
if last_card_Dealer.equal_face(last_card_Player):
print(last_card_Dealer, last_card_Player, "of equal rank")
elif last_card_Dealer.get_face_index() > last_card_Player.get_face_index():
print(last_card_Dealer, "of higher rank than",last_card_Player)
else:
print(last_card_Player, "of higher rank than",last_card_Dealer)
if last_card_Dealer.equal_suit(last_card_Player):
print(last_card_Dealer,'of equal suit with',last_card_Player)
else:
print(last_card_Dealer,'of different suit than',last_card_Player)