# My name: # Date: # Assignment: Extra Credit 2 # # I have not looked any anybody's code while completing this assignment, and # I have not shown my code to anybody else. I am allowed to talk about how to # solve the problems with others, and if I did so I will list them below. # My Collaboration Statement: #My functions go here: def rotateText( textString, numToRotate): #replace with your code: pass def blocksInPyramidHeight( height): #replace with your code: pass def binaryToDecimal(binStr): #replace with your code: pass def blocksInPyramidWidth( maxWidth): #replace with your code: pass def everyOtherLetter( aString ): #replace with your code: pass def sumNestedList( aNestedList): #replace with your code: pass #This function takes two parameters. The first is a function, and the second #is a list of test cases. If the function returns the correct values for #each test case, it passes. Otherwise, it fails! This function is a helper #function for the main test() function below. def testFunction(func,cases): allPassed = True for test in cases: if (test[0] == 0): result = func() elif (test[0] == 1): result = func(test[1]) elif (test[0] == 2): result = func(test[1], test[2]) if result != test[-1]: print "FAIL: Input:", for x in range(1,test[0]+1): print test[x] print "gives output:", result, "and I was expecting:",test[-1] allPassed = False if (allPassed): print "PASSED all tests, Congrats!\n" #A test function that can be used to test student code: def test(): #Try testing the rotateText() function: print "1. rotateText()" try: testCases = [ (2,'Guvf vf n 923. grfg.',13, 'This is a 923. test.'), (2,'Iwxh xh p 923. ithi.',11, 'This is a 923. test.') ] testFunction(rotateText, testCases) except: print "Error: unable to test the rotateText function!" raise print "2. blocksInPyramidHeight()" try: testCases = [ (1, 1, 1), (1, 2, 3), (1, 3, 6), (1, 4, 10), ] testFunction(blocksInPyramidHeight, testCases) except: print "Error: unable to test the blocksInPyramidHeight function!" raise print "3. binaryToDecimal()" try: testCases = [ (1, "0000", 0), (1, "11", 3), (1, "0001", 1), (1, "1001", 9), (1, "1111111111", 1023) ] testFunction(binaryToDecimal, testCases) except: print "Error: unable to test the binaryToDecimal function!" raise print "4. blocksInPyramidWidth()" try: testCases = [ (1, 1, 1), (1, 2, 3), (1, 3, 6), (1, 4, 10), ] testFunction(blocksInPyramidWidth, testCases) except: print "Error: Unable to test the blocksInPyramidWidth function!" raise print "5. everyOtherLetter()" try: testCases = [ (1, "This is a test.", "Ti sats."), (1, "CS 1301 rocks!", "C 31rcs"), (1, "USSRE7R==ridde1e0tt", "USER=id10t"), ] testFunction(everyOtherLetter, testCases) except: print "Error: Unable to test the everyOtherLetter function!" raise print "6. sumNestedList()" try: testCases = [ (1, [4,5, [2,3, [1.5,2] ] ], 17.5), (1, [1,2,3], 6), (1, [4.5, True, "Not a Num!", [2,3,"a"],44.5], 54.0), (1, [2.7, 44, [10, 15, [0,0,5,-10],44.5],8], 119.2) ] testFunction(sumNestedList,testCases) except: print "Error: Unable to test the sumNestedList() function!" raise