Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def test_get_word_score():
- """
- Unit test for get_word_score
- """
- print 'start test'
- failure=False #This line should be the first line inside the for loop to serve as a 'reset'
- # dictionary of words and scores
- words = {("", 7):0, ("it", 7):2, ("was", 7):6, ("scored", 7):9, ("waybill", 7):65, ("outgnaw", 7):61, ("outgnawn", 8):62}
- for (word, n) in words.keys():
- score = get_word_score(word, n)
- print 'testing'
- if score != words[(word, n)]:
- print "FAILURE: test_get_word_score()"
- print "\tExpected", words[(word, n)], "points but got '" + str(score) + "' for word '" + word + "', n=" + str(n)
- #'outgnawn' enters here with a failure so failure = True.
- #unfortunately, once it repeats the loop failure's value is not reset to False
- #so failure's value is now ALWAYS True while it stays inside this for loop
- failure=True
- if not failure:
- #The next words expected to enter this parts like 'scored' and 'it' will not enter this
- #since they are tested after 'outgnawn' (which resulted in a failure), failure's value is now ALWAYS True.
- #Hence, you never get the 'SUCCESS' message. :)
- print "SUCCESS: test_get_word_score()"
- print 'end test'
- #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