def test_shuffle(self): """Should shuffle a full deck. If any are missing it should return a valueError 'Only full decks can be shuffled'""" #Deal 2 decks, shuffle 1 and see if they are different deck1 = self.deck._deal(52) self.deck = Deck(Card) self.deck.shuffle() deck2 = self.deck._deal(52) self.assertFalse(deck1 == deck2) #Deal 1 card from a deck and see if it lets you shuffle it self.deck = Deck(Card) raised_exception = False try: self.deck._deal(1) self.deck.shuffle() except ValueError as exception: if (str(exception) == "Only full decks can be shuffled"): raised_exception = True self.assertTrue(raised_exception, "Did not return: Only full decks can be shuffled")
# # Logic: # 0. Player places bets # 1. Dealer deals # 2. Player hits or stays (while loop) # - Check for blackjack or bust # 3. Once Player stays, it's the Dealer's turn # 4. Dealer hits until they beat the Player or the Dealer busts (while loop) # - Check conditions for game end in every round (over Players sum, blackjack or bust) # 5. Players credit modified based on bet # 6. Replay? from black_jack import Card, Player, deal, Deck, show_cards, place_bet, check_game_end import time deck = Deck() player = Player('Player', 100) dealer = Player('Dealer', 300) players = [dealer, player] game_on = True while (game_on == True): deck.full_new() deck.shuffle() bet = place_bet(player) deal(players, deck) players_turn = True player_busted = False while players_turn: choice = input('Hit or Stay? Press H or S and then Enter.\n') if choice.lower() == 'h':
def test_create_deck(self): deck = Deck() deck.add_cards() self.assertEqual(type(deck.cards), type([])) del deck
def test_cards_out(self): deck = Deck() deck.add_cards() self.assertIsInstance((deck.cards_out(2)[0]), Card) del deck
def test_deck_size(self): deck = Deck() deck.add_cards() result = deck.cards self.assertEqual(len(result), 52) del deck
def setUp(self): self.deck = Deck(Card)
class Deck_test(unittest.TestCase): def setUp(self): self.deck = Deck(Card) def tearDown(self): pass def test_init(self): """Each instance should have a cards attribute with all 52 possible instances of Card""" all_cards = [ Card(suit, value) for suit in Card.valid_suits for value in Card.valid_values ] isEqual = True cards_from_deck = str(self.deck.deal_hand(52)) for card in all_cards: if not str(card) in cards_from_deck: isEqual = False self.assertTrue( isEqual, "Did not end up with all 52 possible instances of Card") def test_count(self): """Should return how many cards remain in a deck""" self.assertEqual(self.deck.count(), 52) self.deck.deal_card() self.assertEqual(self.deck.count(), 51) def test_repr(self): """Should return how many cards are left in a deck eg. 'Deck of 52 cards'""" self.assertEqual(str(self.deck), "Deck of 52 cards") self.deck.deal_card() self.assertEqual(str(self.deck), "Deck of 51 cards") def test_deal(self): """Accepts a number and removes that many cards from a deck. If there are no cards left it returns a valueError 'All cards have been dealt'""" all_cards = self.deck._deal(52) self.assertEqual(self.deck.count(), 0) raised_exception = False try: self.deck._deal(1) except ValueError as exception: if (str(exception) == "All cards have been dealt"): raised_exception = True self.assertTrue(raised_exception, "Did not return: All cards have been dealt") def test_shuffle(self): """Should shuffle a full deck. If any are missing it should return a valueError 'Only full decks can be shuffled'""" #Deal 2 decks, shuffle 1 and see if they are different deck1 = self.deck._deal(52) self.deck = Deck(Card) self.deck.shuffle() deck2 = self.deck._deal(52) self.assertFalse(deck1 == deck2) #Deal 1 card from a deck and see if it lets you shuffle it self.deck = Deck(Card) raised_exception = False try: self.deck._deal(1) self.deck.shuffle() except ValueError as exception: if (str(exception) == "Only full decks can be shuffled"): raised_exception = True self.assertTrue(raised_exception, "Did not return: Only full decks can be shuffled") def test_deal_card(self): """Should deal one card from the deck""" oneCard = Card("Hearts", "3") card = self.deck.deal_card() self.assertEqual(len(card), 1) self.assertEqual(type(card[0]), type(oneCard)) self.assertEqual(self.deck.count(), 51) def test_deal_hand(self): """Accepts a number and deals that many cards from the deck in a list""" oneCard = Card("Hearts", "3") cards = self.deck.deal_hand(5) self.assertEqual(len(cards), 5) for card in cards: self.assertEqual(type(card), type(oneCard)) self.assertEqual(self.deck.count(), (52 - 5))