# THIS CODE IS SUPPOSED TO: Gets a positive one to three-digit integer from # the user, and adds together all of its digits. For example, 123 # would return 6. Hint: remember you can use division! # It has a bug; try to write test cases to reveal the bug # # Do not look at the code. # You only need a specification to create test cases. # def template(number1): hundreds = number1 % 100 tens = (number1 % 100) // 10 singles = number1 % 10 sum = hundreds + tens + singles return sum #this returns the sum of the numbers to the user actualResults = [] expectedResults = [] #WRITE YOUR TESTS BELOW FOLLOWING THE FORMAT actualResults.append(template(0)) expectedResults.append(0) #===================================# ''' actualResults.append(template(111)) expectedResults.append(3) actualResults.append(template(321)) expectedResults.append(6) actualResults.append(template(123)) expectedResults.append(6) ''' #===================================# ctr = 0 found = False while ctr < len(actualResults): actual = actualResults[ctr] expected = expectedResults[ctr] print(str(expected) + " : " + str(actual)) if (actual != expected): found = True ctr = ctr + 1 if (found == True): print("Your test suite found the bug!!") else: print("Try writing more tests, you didn't find the bug yet.") ''' correct code hundreds = number1 // 100 tens = (number1 % 100) // 10 singles = number1 % 10 '''