Exemple #1
0
 def test_remove(self):
     card1=hw5.Card(1,5)
     card2=hw5.Card(2,5)
     card3 = hw5.Card(0, 5)
     card_list=[card1,card2,card3]
     hand=ec2.Hand(card_list)
     hand.remove_pairs()
     return self.assertEqual(len(hand.init_card),1)
Exemple #2
0
    def test_q2(self):
        '''
        1. fill in your test method for question 1:
        Test that if you create a card instance with suit 1, its suit_name will be "Clubs"
        
        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(hw5_cards.Card(1,12).suit_name,'Clubs')
        return hw5_cards.Card(1,12).suit_name,'Clubs'    
Exemple #3
0
    def test_q3(self):
        '''
        1. fill in your test method for question 3:
        Test that if you invoke the __str__ method of a card instance that is created with suit=3, rank=13, it returns the string "King of Spades"

        
        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(hw5_cards.Card(3,13).__str__(),'King of Spades')
        return hw5_cards.Card(3,13).__str__(),'King of Spades'
Exemple #4
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.

        '''
        d2 = hw5_cards.Deck()
        self.assertIsInstance(d2.deal_card(), type(hw5_cards.Card()))
        return d2.deal_card(), type(hw5_cards.Card())
Exemple #5
0
    def __init__(self):

        self.cards = []
        for suit in range(4):
            for rank in range(1, 14):
                card = hw5_cards.Card(suit, rank)
                self.cards.append(card)  # appends in a sorted order
    def test_q3(self):
        '''
        1. fill in your test method for question 3:
        Test that if you invoke the __str__ method of a card instance that is created with suit=3, rank=13, it returns the string "King of Spades"

        
        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.

        '''
        q3 = hw5_cards.Card(3, 13)
        q3_word = q3.__str__()
        
        self.assertEqual(q3_word, 'King of Spades')
        self.assertNotEqual(q3_word, 'King of Clubs')
        self.assertIsNot(q3_word, int)
        self.assertIsInstance(q3_word, str)
        self.assertTrue(q3_word == 'King of Spades')
        self.assertIsNot(q3_word, 1)
        self.assertFalse(q3_word != 'King of Spades')
        self.assertTrue(q3_word != 'Queen of Diamonds')
        
        return q3_word, 'King of Spades' 
Exemple #7
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.

        '''
        test_deck = hw5_cards.Deck()

        num_card1 = len(test_deck.cards)
        test_card = hw5_cards.Card(suit=3, rank=13)

        test_deck.replace_card(test_card)
        num_card2 = len(test_deck.cards)

        X = num_card2 - num_card1
        Y = 0
        self.assertEqual(X, Y)

        return X, Y
Exemple #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.

        '''
        suit = random.randint(0, 3)
        rank = random.randint(1, 13)
        c = hw5_cards.Deck()
        len_before = len(c.cards)
        card = hw5_cards.Card(suit, rank)
        c.replace_card(card)
        len_after = len(c.cards)
        self.assertEqual(len_before, len_after)

        X = len_before
        Y = len_after
        return X, Y
Exemple #9
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.

        '''
        q7 = hw5_cards.Deck()
        q71 = hw5_cards.Deck(
        )  # create this to match the autograder expected output
        q7.deal_card(
        )  # deal_card() will remote the card from q7, and return the removed card (3,13)
        q71.deal_card(
        )  # q71 is used to test after deal function, the length of q71 should be 51 not 52
        q7.replace_card(
            hw5_cards.Card(3, 13)
        )  # use hw5_cards.Card(3,13) to add back the one being pop out which is King of Spades (3,13)
        self.assertEqual(
            len(q7.cards), 52
        )  #q7 is the list after pop function and replace function >> length should be 52
        self.assertNotEqual(
            len(q7.cards), 53
        )  #q7 is the list after pop function and replace function >> length should be 52
        return len(q71.cards) + 1, len(
            q7.cards
        ), 52  # q71 is used to test the length after deal, q7 is the length after deal and replace
Exemple #10
0
    def test_remove_card(self):
        '''
        Test that if you invoke the remove_card method on a Hand, the Hand has one fewer cards in it afterwards.
        Test that if you invoke the remove_card method with a Hand that is not in the Hand, the Hand size is not affected.

        '''

        c1 = hw5_cards.Card(1, 1)
        c2 = hw5_cards.Card(0, 2)
        c3 = hw5_cards.Card(0, 2)
        c4 = hw5_cards.Card(3, 3)
        h1 = hw5_cards_ec1.Hand([c1, c2])
        self.assertEqual(len(h1.init_cards), 2)
        h1.remove_card(c3)
        self.assertEqual(len(h1.init_cards), 1)
        h1.remove_card(c4)
        self.assertEqual(len(h1.init_cards), 1)
Exemple #11
0
    def test_add_card(self):
        '''
        Test that if you invoke the add_card method on a Hand, the Hand has one more cards in it afterwards.
        Test that if you invoke the add_card method with a card that is already in the Hand, the Hand size is not affected.

        '''

        c1 = hw5_cards.Card(1, 1)
        c2 = hw5_cards.Card(0, 2)
        c3 = hw5_cards.Card(3, 3)
        c4 = hw5_cards.Card(0, 2)
        h1 = hw5_cards_ec1.Hand([c1, c2])
        self.assertEqual(len(h1.init_cards), 2)
        h1.add_card(c3)
        self.assertEqual(len(h1.init_cards), 3)
        h1.add_card(c4)
        self.assertEqual(len(h1.init_cards), 3)
Exemple #12
0
    def test_construct_Card(self):
        c1 = hw5_cards.Card(0, 2)
        c2 = hw5_cards.Card(1, 1)

        self.assertEqual(c1.suit, 0)  #expect suit to be 0
        self.assertEqual(c1.suit_name,
                         "Diamonds")  #expect suit_name to be Diamonds
        self.assertEqual(c1.rank, 2)  #expect rank to be 2
        self.assertEqual(c1.rank_name, "2")  #expect rank_name to be 2

        self.assertIsInstance(c1.suit, int)  #expect suit to be an integer
        self.assertIsInstance(c1.suit_name,
                              str)  #expect suit_name to be a string
        self.assertIsInstance(c1.rank, int)  #expect rank to be an integer
        self.assertIsInstance(c1.rank_name,
                              str)  #expect rank_name to be a string

        self.assertEqual(c2.suit,
                         1)  #Testing second object - expect suit to be 1
        self.assertEqual(c2.suit_name, "Clubs")  #expect suit_name to be Clubs
        self.assertEqual(c2.rank, 1)
        self.assertEqual(c2.rank_name, "Ace")
Exemple #13
0
    def test_q1(self):
        '''
        1. fill in your test method for question 1:
        Test that if you create a card with rank 12, its rank_name will be "Queen"
        
        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.

        '''
        card = hw.Card(rank=12)
        return self.assertEqual(card.rank_name, "Queen")
Exemple #14
0
    def test_draw(self):
        '''
        Test that if you invoke the draw method from a deck and add it to the hand, the Hand has one more cards in it afterwards.
        Test that if you invoke the draw method with a Hand that caused a side effect: the deck will be depleted by one card.

        '''

        c1 = hw5_cards.Card(1, 1)
        c2 = hw5_cards.Card(0, 2)
        d1 = hw5_cards.Deck()
        h1 = hw5_cards_ec1.Hand([c1, c2])
        self.assertEqual(len(h1.init_cards), 2)
        self.assertEqual(len(d1.cards), 52)
        h1.draw(d1)
        self.assertEqual(len(h1.init_cards), 3)
        self.assertEqual(len(d1.cards), 51)

        d2 = hw5_cards.Deck()
        self.assertEqual(len(d2.cards), 52)
        for i in range(len(d2.cards)-1):
            d2.cards.pop(-1)
        h1.draw(d2)
        self.assertEqual(len(h1.init_cards), 4)
        self.assertEqual(len(d2.cards), 0)
Exemple #15
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.

        '''
        d5 = hw5_cards.Deck()
        d5.replace_card(hw5_cards.Card(1, 1))
        test8Result = self.assertEqual(len(d5.cards), 52)
        return (len(d5.cards), 52)
Exemple #16
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.Deck()
        card = hw5_cards.Card(
        )  # card to be added, which is already in the deck
        num_cards = len(deck.cards)  # number of cards after deal card
        deck.replace_card(card)  # try to add the card
        self.assertEqual(num_cards, len(deck.cards))
Exemple #17
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.

        '''
        c7 = hw5_cards.Card(1, 1)
        d4 = hw5_cards.Deck()
        c7 = d4.deal_card()
        d4.replace_card(c7)
        test7Result = self.assertEqual(len(d4.cards), 52)
        return (len(d4.cards), 52)
Exemple #18
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.

        '''
        q5 = hw5_cards.Deck()
        q6 = hw5_cards.Card(3, 13)
        q51 = q5.deal_card()
        self.assertEqual(q51.__str__(), q6.__str__())
        self.assertEqual(q51.suit, 3)
        self.assertEqual(q51.suit_name, "Spades")
        self.assertEqual(q51.rank, 13)
        self.assertEqual(q51.rank_name, "King")

        return q51, (3, 13)
Exemple #19
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.

        '''
        q8 = hw5_cards.Deck()
        q8.replace_card(
            hw5_cards.Card(3, 13)
        )  # use hw5_cards.Card(3,13) to add the existing one  which is King of Spades (3,13)
        self.assertEqual(
            len(q8.cards), 52
        )  # if the a card that is already in the deck, the deck size is not affected >> length should be 52
        self.assertNotEqual(
            len(q8.cards),
            53)  # Other test for length of the number of the card in the deck
        return len(q8.cards), 52
    def test_q1(self):
        '''
        1. fill in your test method for question 1:
        Test that if you create a card with rank 12, its rank_name will be "Queen"
        
        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.

        '''
        q1 = hw5_cards.Card(2, 12)
        
        self.assertEqual(q1.rank_name, 'Queen')
        self.assertNotEqual(q1.rank_name, 'King')
        self.assertIsInstance(q1.rank_name, str)
        self.assertTrue(q1.rank_name == 'Queen')
        self.assertFalse(q1.rank_name != 'Queen')
        self.assertIs(q1.rank_name, 'Queen')
        self.assertIsNot(q1.rank_name, 'Jack')
        self.assertIsNot(q1.rank_name, 10)
        
        return q1.rank_name, 'Queen'
Exemple #21
0
 def test_q2(self):
     c = cards.Card(1,2)
     self.assertEqual(c.suit_name, "Clubs")
Exemple #22
0
 def test_q1(self):
     c = cards.Card(0,12)
     self.assertEqual(c.rank_name,'Queen')
 def test_removecard(self):
     h = cards_ec1.Hand([cards.Card(1, 2)])
     card = cards.Card(1, 2)
     h.remove_card(card)
     self.assertEqual(len(h.init_cards), 0)
Exemple #24
0
    def test_construct_Hand(self):
        c1 = hw5_cards.Card(1, 1)
        c2 = hw5_cards.Card(0, 2)
        h1 = hw5_cards_ec1.Hand([c1, c2])

        self.assertIsInstance(h1.init_cards, list)