Ejemplo n.º 1
0
    def test_q4(self):
        '''
        1. fill in your test method for question 4:
        Test that if you create a eck instance, it will have 52 cards in its cards instance variable
        
        2. remove the pass command
        
        3. uncomment the return command and 
        3b. change X, Y to the values from your assert statement
        ### please note: normally unit test methods do not have return statements. But returning will allow for unit testing of your unit test, and allow you to check your answer with the autograder.  This is optional today.

        '''
        self.assertEqual(len(hw5_cards_ec1.Deck().cards), 52)
        return len(hw5_cards_ec1.Deck().cards), 52
Ejemplo n.º 2
0
    def test_q5(self):
        '''
        1. fill in your test method for question 5:
        Test that if you invoke the deal_card method on a deck, it will return a card instance.
        
        2. remove the pass command
        
        3. uncomment the return command and 
        3b. change X, Y to the values from your assert statement
        ### please note: normally unit test methods do not have return statements. But returning will allow for unit testing of your unit test, and allow you to check your answer with the autograder.  This is optional today.

        '''
        self.assertIsInstance(hw5_cards_ec1.Deck().deal_card(),
                              hw5_cards_ec1.Card)
        return hw5_cards_ec1.Deck().deal_card(), hw5_cards_ec1.Card
Ejemplo n.º 3
0
 def testDraw(self):
     deck1 = hw5_cards_ec1.Deck()
     deck1.shuffle()
     len_deck_before = len(deck1.cards)
     hand1 = hw5_cards_ec1.Hand([])
     len_hand_before = len(hand1.init_card)
     hand1.draw(deck1)
     len_dec_after = len(deck1.cards)
     len_hand_after = len(hand1.init_card)
     self.assertEqual(len_hand_before + 1, len_hand_after)
     self.assertEqual(len_dec_after, len_deck_before - 1)
Ejemplo n.º 4
0
    def test_q10(self):
        '''
        test that draw function functions as intended
        '''
        deck = hw5_cards_ec1.Deck()
        hand = hw5_cards_ec1.Hand([])

        self.assertEqual(hand.cards, [])
        self.assertEqual(len(deck.cards), 52)

        hand.draw(deck)
        self.assertEqual(len(hand.cards), 1)
        self.assertEqual(len(deck.cards), 51)
Ejemplo n.º 5
0
 def testDraw(self):
     d1 = hw5_cards_ec1.Deck()
     h1 = hw5_cards_ec1.Hand()
     d1_start_length = len(d1.cards)
     h1_start_length = len(h1.cards)
     h1.draw(d1)
     d1_end_length = len(d1.cards)
     h1_end_length = len(h1.cards)
     start_cards = d1_start_length + h1_start_length
     end_cards = d1_end_length + h1_end_length
     self.assertEqual(start_cards,end_cards)
     self.assertEqual(d1_start_length,d1_end_length+1)
     self.assertEqual(h1_start_length,h1_end_length-1)
Ejemplo n.º 6
0
 def test_draw(self):
     c1 = hw5_cards_ec1.Card(0, 1)
     c2 = hw5_cards_ec1.Card(0, 2)
     d1 = hw5_cards_ec1.Deck()
     d1.shuffle()
     h1 = hw5_cards_ec1.Hand(d1.deal_hand(5))
     self.assertEqual(len(h1.init_cards), 5)
     self.assertEqual(len(d1.cards), 47)
     h1.draw(d1)
     self.assertEqual(len(h1.init_cards), 6)
     self.assertEqual(len(d1.cards), 46)
     h1.draw(d1)
     self.assertEqual(len(h1.init_cards), 7)
     self.assertEqual(len(d1.cards), 45)
Ejemplo n.º 7
0
    def test_draw(self):
        '''
        Test that draw( ) works as specified.
        '''
        d = hw5_cards_ec1.Deck()  # Initialize a deck
        h = hw5_cards_ec1.Hand([])  # Initialize a hand with no cards

        h.draw(d)  # Draw a card from the deck
        self.assertEqual(len(h.init_cards), 1)  # Check if one card is added
        self.assertEqual(
            len(d.cards), 51
        )  # Check if the number of cards in the deck has decreased by one (side effect)
        self.assertTrue(
            str(h.init_cards[0])
            not in [str(card) for card in d.cards
                    ])  # Check if the drawed card is not in the deck
Ejemplo n.º 8
0
    def test_q8(self):
        '''
        1. fill in your test method for question 8:
        Test that if you invoke the replace_card method with a card that is already in the deck, the deck size is not affected.(The function must silently ignore it if you try to add a card that’s already in the deck)

        
        2. remove the pass command
        
        3. uncomment the return command and 
        3b. change X, Y to the values from your assert statement
        ### please note: normally unit test methods do not have return statements. But returning will allow for unit testing of your unit test, and allow you to check your answer with the autograder.  This is optional today.

        '''
        deck = hw5_cards_ec1.Deck()
        deck.replace_card(hw5_cards_ec1.Card(0, 1))
        self.assertEqual(len(deck.cards), 52)
        return len(deck.cards), 52
Ejemplo n.º 9
0
    def test_q6(self):
        '''
        1. fill in your test method for question 6:
        
        Test that if you invoke the deal_card method on a deck, the deck has one fewer cards in it afterwards.
        
        2. remove the pass command
        
        3. uncomment the return command and 
        3b. change X, Y to the values from your assert statement
        ### please note: normally unit test methods do not have return statements. But returning will allow for unit testing of your unit test, and allow you to check your answer with the autograder.  This is optional today.

        '''
        deck = hw5_cards_ec1.Deck()
        deck.deal_card()
        self.assertEqual(len(deck.cards), 51)
        return len(deck.cards), 51
Ejemplo n.º 10
0
    def test_draw(self):
        deck = hw5_cards_ec1.Deck()
        init_cards = [
            hw5_cards_ec1.Card(3, 12),
            hw5_cards_ec1.Card(0, 13),
            hw5_cards_ec1.Card(2, 6),
            hw5_cards_ec1.Card(1, 5),
            hw5_cards_ec1.Card(3, 3)
        ]
        hand = hw5_cards_ec1.Hand(init_cards)

        # Remove the cards that are in hand from the deck
        deck_str = []
        for i in deck.cards:
            deck_str.append(i.__str__())

        hand_str = []
        for i in hand.cards:
            hand_str.append(i.__str__())

        for i in hand_str:
            for j in deck_str:
                if j == i:
                    idx = deck_str.index(j)
                    deck.cards.pop(idx)
        # Make sure the cards in hand and the deck cards are compensate with each other.
        initial_deck_length = len(deck.cards)
        initial_hand_length = len(hand.cards)
        self.assertEqual(initial_deck_length + initial_hand_length,
                         52,
                         msg="Compensate pair")

        # Make sure the draw function works
        hand.draw(deck)
        after_deck_length = len(deck.cards)
        after_hand_length = len(hand.cards)
        self.assertEqual(after_deck_length + after_hand_length,
                         52,
                         msg="Compensate pair")
        self.assertEqual(after_deck_length,
                         initial_deck_length - 1,
                         msg="Remove one from deck")
        self.assertEqual(after_hand_length,
                         initial_hand_length + 1,
                         msg="Add one to the hand")
Ejemplo n.º 11
0
    def test_q7(self):
        '''
        1. fill in your test method for question 7:
        Test that if you invoke the replace_card method, the deck has one more card in it afterwards. (Please note that you want to use deal_card function first to remove a card from the deck and then add the same card back in)

        
        2. remove the pass command
        
        3. uncomment the return command and 
        3b. change X, Y to the values from your assert statement
        ### please note: normally unit test methods do not have return statements. But returning will allow for unit testing of your unit test, and allow you to check your answer with the autograder.  This is optional today.

        '''
        deck = hw5_cards_ec1.Deck()
        deck_size_before = len(deck.cards)
        card = deck.deal_card()
        deck.replace_card(card)
        deck_size_after = len(deck.cards)
        self.assertEqual(deck_size_before, deck_size_after, 52)
        return deck_size_before, deck_size_after, 52
Ejemplo n.º 12
0
    def test_draw(self):
        # construct hand_1, instance of Hand
        cards_already_in_hands = \
            [hw5_cards_ec1.Card(0, 1), hw5_cards_ec1.Card(1, 4), hw5_cards_ec1.Card(3, 11), hw5_cards_ec1.Card(3, 12)]
        hand_1 = hw5_cards_ec1.Hand(cards_already_in_hands)

        # construct deck, instance of Deck
        deck = hw5_cards_ec1.Deck()

        # eliminate cards already in hand_1 from deck
        deck_existing_card_str = []
        for deck_card in deck.cards:
            deck_existing_card_str.append(deck_card.__str__())
        hand_existing_card_str = []
        for hand_card in hand_1.init_card:
            hand_existing_card_str.append(hand_card.__str__())
        deck_str_to_use = []
        for deck_card_str in deck_existing_card_str:
            if deck_card_str not in hand_existing_card_str:
                deck_str_to_use.append(deck_card_str)
        deck_to_use = []
        for deck_card in deck.cards:
            if deck_card.__str__() in deck_str_to_use:
                deck_to_use.append(deck_card)
        deck.cards = deck_to_use

        # test starts
        current_len_hand_cards = len(hand_1.init_card)
        current_len_deck_cards = len(deck.cards)

        # make sure they compensate for each other
        self.assertEqual(current_len_hand_cards + current_len_deck_cards, 52)
        hand_1.draw(deck)
        after_len_hand_cards = len(hand_1.init_card)
        after_len_deck_cards = len(deck.cards)
        self.assertEqual(after_len_hand_cards, current_len_hand_cards + 1)
        self.assertEqual(after_len_deck_cards, current_len_deck_cards - 1)