[ create a new paste ] login | about

Link: http://codepad.org/hPApKb1R    [ raw code | fork ]

Python, pasted on Feb 6:
def test_update_hand():
    """
    Unit test for update_hand
    """
    # test 1
    hand = {'a':1, 'q':1, 'l':2, 'm':1, 'u':1, 'i':1}
    word = "quail"

    hand2 = update_hand(hand.copy(), word)
    expected_hand1 = {'l':1, 'm':1}
    expected_hand2 = {'a':0, 'q':0, 'l':1, 'm':1, 'u':0, 'i':0}
    if hand2 != expected_hand1 and hand2 != expected_hand2:
        print "FAILURE: test_update_hand('"+ word +"', " + str(hand) + ")"
        print "\tReturned: ", hand2, "-- but expected:", expected_hand1, "or", expected_hand2

        return # exit function
        
    # test 2
    hand = {'e':1, 'v':2, 'n':1, 'i':1, 'l':2}
    word = "evil"

    hand2 = update_hand(hand.copy(), word)
    expected_hand1 = {'v':1, 'n':1, 'l':1}
    expected_hand2 = {'e':0, 'v':1, 'n':1, 'i':0, 'l':1}
    if hand2 != expected_hand1 and hand2 != expected_hand2:
        print "FAILURE: test_update_hand('"+ word +"', " + str(hand) + ")"        
        print "\tReturned: ", hand2, "-- but expected:", expected_hand1, "or", expected_hand2

        return # exit function

    # test 3
    hand = {'h': 1, 'e': 1, 'l': 2, 'o': 1}
    word = "hello"

    hand2 = update_hand(hand.copy(), word)
    expected_hand1 = {}
    expected_hand2 = {'h': 0, 'e': 0, 'l': 0, 'o': 0}
    if hand2 != expected_hand1 and hand2 != expected_hand2:
        print "FAILURE: test_update_hand('"+ word +"', " + str(hand) + ")"                
        print "\tReturned: ", hand2, "-- but expected:", expected_hand1, "or", expected_hand2
        
        return # exit function

    print "SUCCESS: test_update_hand()"


Output:
No errors or program output.


Create a new paste based on this one


Comments: