Ejemplo n.º 1
0
    def test_update_hand(self):
        """
        Unit test for update_hand
        """
        # test 1
        handOrig = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1}
        handCopy = handOrig.copy()
        word = "quail"

        updated_hand = update_hand(handCopy, word)
        expected_hand = {'a':0, 'q':0, 'l':1, 'm':1, 'u':0, 'i':0}
        # Check proper response
        self.assertEqual(updated_hand, expected_hand)
        # Check did not modify handCopy
        self.assertEqual(handCopy, handOrig)
        
        # test 2
        handOrig = {'e':1, 'v':2, 'n':1, 'i':1, 'l':2}
        handCopy = handOrig.copy()
        word = "Evil"

        updated_hand = update_hand(handCopy, word)
        expected_hand = {'e':0, 'v':1, 'n':1, 'i':0, 'l':1}
        #check proper response with capital letter in word
        self.assertEqual(updated_hand, expected_hand)
        #Check did not modify handCopy
        self.assertEqual(handCopy, handOrig)

        # test 3
        handOrig = {'h': 1, 'e': 1, 'l': 2, 'o': 1}
        handCopy = handOrig.copy()
        word = "HELLO"

        updated_hand = update_hand(handCopy, word)
        expected_hand = {'h': 0, 'e': 0, 'l': 0, 'o': 0}
        #Check proper response with all CAPS word
        self.assertEqual(updated_hand, expected_hand)
        #Check did not modify handCopy
        self.assertEqual(handCopy, handOrig)
Ejemplo n.º 2
0
 def test_update_hand_3(self): 
     # test 3
     handOrig = {'h': 1, 'e': 1, 'l': 2, 'o': 1}
     handCopy = handOrig.copy()
     word = "HELLO"
     msg_part1 = "Failed when updating hand '%s' with word '%s'. " %(str(handOrig), word)
     try:
         hand2 = ps3.update_hand(handCopy, word)
     except NotImplementedError as e:
         self.fail(NOT_IMPLEMENTED)
     expected_hand1 = {}
     expected_hand2 = {'h': 0, 'e': 0, 'l': 0, 'o': 0}
     error_msg = msg_part1 + "Returned: " + str(hand2) + "\n-- but expected: "+ str(expected_hand1)+ " or "+ str(expected_hand2)
     self.assertTrue(hand2 == expected_hand1 or hand2 == expected_hand2, error_msg)
     error_msg = msg_part1 + "Original hand was "+ str(handOrig) + " but implementation of update_hand mutated the original hand! Now the hand looks like this:" + str(handCopy)
     self.assertEqual(handCopy, handOrig, error_msg)
Ejemplo n.º 3
0
 def test_update_hand(self):
     hand = {'h': 1, 'a': 1, 't': 1, 'b': 1, 'j': 2}
     word = 'hat'
     result = ps3.update_hand(hand, word)
     print("t\ Testing show_possible matches ")
     self.assertEqual(result, {'b': 1, 'j': 2})