def test3_drawCard(self): deck = _createDeck(rank=["2", "3", "4"], suit=["spades", "hearts", "clubs", "diamonds"]) players = {"Jim": _createHand()} for x in range(0, len(deck)): for name in players.keys(): gofish.drawCard(name, deck, players[name]) self.assertTrue(len(players["Jim"]) == 0)
def test_draw(self): hand = {} drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) self.assertEqual(len(self.deck), 52-5)
def test2_drawCard(self): deck = _createDeck(rank=[ "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" ], suit=["spades", "hearts", "clubs"]) players = {"Jim": _createHand()} for x in range(0, len(deck)): for name in players.keys(): gofish.drawCard(name, deck, players[name]) self.assertTrue(len(players["Jim"]) == 13)
def test_handContainsExpectedSuits(self): hand = {} drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) # Manipulate deck to force player to draw a 2 of Clubs self.deck.append(("2", "clubs")) drawCard("Test", self.deck, hand) expectedValues = [['clubs'], ['clubs'], ['hearts'], ['hearts', 'clubs']] self.assertEqual(sorted(hand.values()), expectedValues)
def test_handSizeIs4(self): hand = {} drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) # Manipulate deck to force player to draw a 2 of Clubs self.deck.append(("2", "clubs")) drawCard("Test", self.deck, hand) # Will fail with current bug self.assertEqual(len(hand), 4)
def test1_drawCard(self): deck = _createDeck() players = { "Jim": _createHand(), "Kathy": _createHand(), "Zach": _createHand() } for x in range(0, len(deck)): for name in players.keys(): gofish.drawCard(name, deck, players[name]) for rank in players[name]: self.assertTrue( len(rank) > 0 and len(rank) < 4) # check that no rank has less 0 or 4+ suits
def test_handContainsExpectedRanks(self): hand = {} drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) # Manipulate deck to force player to draw a 2 of Clubs self.deck.append(("2", "clubs")) drawCard("Test", self.deck, hand) print(sorted(hand)) expectedHand = ['2', '3', '4', '5'] self.assertEqual(sorted(hand), expectedHand)
def test_4OfSameRank(self): hand = {} drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) drawCard("Test", self.deck, hand) # Manipulate deck to force player to draw all four 2s self.deck.append(("2", "clubs")) drawCard("Test", self.deck, hand) expectedValues = [['clubs'], ['clubs'], ['hearts'], ['hearts', 'clubs']] self.assertEqual(sorted(hand.values()), expectedValues) self.deck.append(("2", "diamonds")) drawCard("Test", self.deck, hand) expectedValues = [['clubs'], ['clubs'], ['hearts'], ['hearts', 'clubs', 'diamonds']] self.assertEqual(sorted(hand.values()), expectedValues) self.deck.append(("2", "spades")) drawCard("Test", self.deck, hand) expectedValues = [['clubs'], ['clubs'], ['hearts']] self.assertEqual(sorted(hand.values()), expectedValues) self.assertEqual(len(hand), 3) expectedHand = ['3', '4', '5'] self.assertEqual(sorted(hand), expectedHand)
import random import gofish def new_deck(): rank=["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] suit=["spades", "hearts", "diamonds", "clubs"] deck = [(r, s) for r in rank for s in suit] return deck if __name__ == "__main__": deck = new_deck() random.shuffle(deck) print(deck) hand = {} name = "Henry" for _ in range(len(deck)): gofish.drawCard(name, deck, hand)