Guest User

Untitled

a guest
May 10th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. def test_get_word_score():
  2.     """
  3.    Unit test for get_word_score
  4.    """
  5.     print 'start test'
  6.     failure=False #This line should be the first line inside the for loop to serve as a 'reset'
  7.     # dictionary of words and scores
  8.     words = {("", 7):0, ("it", 7):2, ("was", 7):6, ("scored", 7):9, ("waybill", 7):65, ("outgnaw", 7):61, ("outgnawn", 8):62}
  9.     for (word, n) in words.keys():
  10.         score = get_word_score(word, n)
  11.         print 'testing'
  12.         if score != words[(word, n)]:
  13.             print "FAILURE: test_get_word_score()"
  14.             print "\tExpected", words[(word, n)], "points but got '" + str(score) + "' for word '" + word + "', n=" + str(n)
  15.             #'outgnawn' enters here with a failure so failure = True.
  16.             #unfortunately, once it repeats the loop failure's value is not reset to False
  17.             #so failure's value is now ALWAYS True while it stays inside this for loop
  18.             failure=True
  19.        
  20.         if not failure:
  21.             #The next words expected to enter this parts like 'scored' and 'it' will not enter this
  22.             #since they are tested after 'outgnawn' (which resulted in a failure), failure's value is now ALWAYS True.
  23.             #Hence, you never get the 'SUCCESS' message. :)
  24.             print "SUCCESS: test_get_word_score()"
  25.     print 'end test'
  26.  
  27.     #However, if the words were tested with the 'success' words before the 'failure' words, this function will work as expected
Advertisement
Add Comment
Please, Sign In to add comment