Ejemplo n.º 1
0
class TestDeck(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.card_library = CardLibrary()

    def setUp(self):
        self.example_card_1 = self.card_library.get_card(name="Plains")
        self.example_card_2 = self.card_library.get_card(name="Island")
        self.example_card_3 = self.card_library.get_card(name="Swamp")
        self.example_card_4 = self.card_library.get_card(name="Mountain")
        self.example_card_5 = self.card_library.get_card(name="Forest")
        self.example_deck = Deck([
            self.example_card_1, self.example_card_2, self.example_card_3,
            self.example_card_4, self.example_card_5
        ])

    def test_shuffle(self):
        """
        Checks whether or not the shuffle() method randomly reorders the cards in a Deck.
        """
        self.example_deck.shuffle()
        drawn_card = self.example_deck.draw()
        self.assertIsNot(drawn_card, self.example_card_1)

    def test_draw(self):
        """
        Checks whether or not the draw() method correctly removes and returns a Card from a Deck.
        """
        initial_size = self.example_deck.size
        drawn_card = self.example_deck.draw()
        self.assertIsInstance(drawn_card, Card)
        self.assertEqual(self.example_deck.size, initial_size - 1)

    def test_add_card(self):
        """
        Checks that the Deck.add_card() method adds a Card to a Deck.
        """
        another_card = self.card_library.get_card(name="Wasteland")
        self.assertNotIn(another_card, self.example_deck)
        self.example_deck._add_card(another_card)
        self.assertIn(another_card, self.example_deck)

    def test_add_cards(self):
        """
        Checks that the Deck.add_cards() method adds multiple Cards to a Deck.
        """
        another_card = self.card_library.get_card(name="Wasteland")
        another_card_2 = self.card_library.get_card(name="Strip Mine")
        self.assertNotIn(another_card, self.example_deck)
        self.assertNotIn(another_card_2, self.example_deck)
        self.example_deck._add_cards([another_card, another_card_2])
        self.assertIn(another_card, self.example_deck)
        self.assertIn(another_card_2, self.example_deck)
Ejemplo n.º 2
0
            break
        elif option == 4:
            my_player.check_hand()
        elif option == 5:
            my_player.check_total()
        elif option == 6:
            play_again = False
            print('Thank you for playing, you have {} chips left' .format(my_player.chips))
            exit(0)

    if my_player.bust == 0:
        while game.check_hand_total(my_dealer.hand):
            print('Dealer is picking a card from the deck')
            a, b = my_deck.pick_card()
            my_dealer.hand.append(a)
            if game.check_hand_total(my_dealer.hand):
                if game.game_win_logic(my_dealer.hand, my_player.hand):
                    break
                else:
                    continue
            else:
                print('player wins!')
                my_player.win_bet()
                break
        else:
            my_player.lose_bet()

    my_deck.shuffle()
    my_player.hand = []
    my_dealer.hand = []
    my_player.bet = 0