# CSE 143, AU10, Alyssa Harding # # A basic testing program for sorted list methods. # import all the methods from your sortedlistmethods file from sortedlistmethods import * # Compares the expected result to the result of calling the given function # on the given list, and prints out the results # # function - the name of the function to call # list - the list to call it on # input - any other parameters to pass the function # expected - the expected result # def assert_equals(expected, function, list, input = None): result = function(list) if input == None else function(list, input) print(function.__name__ + '(' + ('' if input == None else str(input)) + ')', end='') if result == expected: print('=', result, "\n\t(This is the expected result!)") else: print("!=", result, "\n\t(The expected result is:", str(expected) + ')') print def assert_result(expected, function, list, input = None): function(list) if input == None else function(list, input) print(function.__name__ + '(' + ('' if input == None else str(input)) + ')', end='') if list == expected: print('=', list, "\n\t(This is the expected result!)") else: print("!=", list, "\n\t(The expected result is:", str(expected) + ')') print() # Size tests list = [1, 2, 3, 4] assert_equals(4, size, list) assert_equals(0, size, []) # Max and min tests assert_equals(1, min, list) assert_equals(4, max, list) # This should raise an exception #assert_equals(None, max, []) # remove tests assert_result([2,3,4], remove, [1,2,3,4], 0) assert_result([1,3,4], remove, [1,2,3,4], 1) # indexOf tests assert_equals(0, indexOf, list, 1) assert_equals(2, indexOf, list, 3) assert_equals(-1, indexOf, list, 42) # contains tests assert_equals(True, contains, list, 1) assert_equals(True, contains, list, 3) assert_equals(False, contains, list, 42) # add tests assert_result([1,1,2,3,4], add, [1,2,3,4], 1) assert_result([1,2,3,4,7], add, [1,2,3,4], 7) assert_result([1,2,2,3,4], add, [1,2,3,4], 2) # removeDuplicates tests assert_result([1,2,3,4], removeDuplicates, [1,1,2,2,3,4]) assert_result([1,2,3,4], removeDuplicates, [1,2,3,4]) assert_result([1,2,3,4], removeDuplicates, [1,2,3,4]) assert_result([1,2,3,4], removeDuplicates, [1,1,2,2,2,3,4,4]) # Add more of your own tests here! You can use the "assert_equals" method if # you like, or call methods and print out the results