def run_test_practice_problem2b(): # ------------------------------------------------------------------------- # TODO: 3. Implement this TEST function. # It TESTS the practice_problem2b function defined below. # Include at least ** 4 ** tests that, taken together, # would form a ** REASONABLY GOOD test set ** # for testing the practice_problem2b function defined below. # (We supplied 3 tests, so you need supply only one more.) # ------------------------------------------------------------------------ # DIFFICULTY AND TIME RATINGS (see top of this file for explanation) # DIFFICULTY: 4 # TIME ESTIMATE: 10 minutes. # -------------------------------------------------------------------- """ Tests the practice_problem2b function. """ print() print('--------------------------------------------------') print('Testing the practice_problem2b function:') print('--------------------------------------------------') format_string = ' practice_problem2b( {}, {} )' test_results = [0, 0] # Number of tests passed, failed. # Test 1: arg1 = [2, 10, 5, -20, 8] correct_arg1_after = [8, 16, 11, -14, 14] expected = None testing_helper.print_function_call_of_test([arg1, 6], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2b(arg1, 6) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # Test 2: arg1 = [1, 1, 2, 3, 10, -11, 12, 0, 0, 1] correct_arg1_after = [1, 1, 2, 3, 10, -11, 12, 0, 0, 1] expected = None testing_helper.print_function_call_of_test([arg1, 0], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2b(arg1, 0) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # Test 3: arg1 = [795, -795, 0] correct_arg1_after = [-1, -1591, -796] expected = None testing_helper.print_function_call_of_test([arg1, -796], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2b(arg1, -796) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # ------------------------------------------------------------------------- # TODO: 3 (continued): Add your ADDITIONAL test(s) below here. # You do NOT have to use the "fancy" parts of the above example tests, # but you MUST test BOTH the returned value AND the mutated list. # ------------------------------------------------------------------------- # SUMMARY of test results: print_summary_of_test_results(test_results)
def run_test_practice_problem2d(): """ Tests the practice_problem2d function. """ print() print('--------------------------------------------------') print('Testing the practice_problem2d function:') print('--------------------------------------------------') format_string = ' practice_problem2d( {}, {} )' test_results = [0, 0] # Number of tests passed, failed. print() print('--------------------------------------------------') print('Testing the practice_problem2d function:') print('--------------------------------------------------') # Test 1: arg1 = [10, -3, 20, 4] correct_arg1_after = [20, -6, 40, 8] arg2 = [5, 0, 8] correct_arg2_after = [5, 0, 8] expected = [10, 0, 16] testing_helper.print_function_call_of_test([arg1, arg2], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2d(arg1, arg2) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print(' Argument 2 is: ', arg2) print(' Argument 2 should be:', correct_arg2_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (arg2 == correct_arg2_after)\ and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # Test 2: arg1 = [] correct_arg1_after = [] arg2 = [] correct_arg2_after = [] expected = [] testing_helper.print_function_call_of_test([arg1, arg2], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2d(arg1, arg2) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print(' Argument 2 is: ', arg2) print(' Argument 2 should be:', correct_arg2_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (arg2 == correct_arg2_after)\ and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # Test 3: arg1 = [1, 2, 3, 0, 1, 2, 3] correct_arg1_after = [2, 4, 6, 0, 2, 4, 6] arg2 = [0] correct_arg2_after = [0] expected = [0] testing_helper.print_function_call_of_test([arg1, arg2], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2d(arg1, arg2) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print(' Argument 2 is: ', arg2) print(' Argument 2 should be:', correct_arg2_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (arg2 == correct_arg2_after)\ and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # Test 4: arg1 = [0] correct_arg1_after = [0] arg2 = [1, 2, 3, 0, 1, 2, 3] correct_arg2_after = [1, 2, 3, 0, 1, 2, 3] expected = [2, 4, 6, 0, 2, 4, 6] testing_helper.print_function_call_of_test([arg1, arg2], test_results, format_string) print() print('BEFORE the function call:') print(' Argument 1 is:', arg1) answer = practice_problem2d(arg1, arg2) print('AFTER the function call:') print(' Argument 1 is: ', arg1) print(' Argument 1 should be:', correct_arg1_after) print(' Argument 2 is: ', arg2) print(' Argument 2 should be:', correct_arg2_after) print('The returned value is: ', answer) print('The returned value should be:', expected) if (arg1 == correct_arg1_after) and (arg2 == correct_arg2_after)\ and (answer == expected): testing_helper.print_colored(" PASSED the above test -- good!", color='blue') test_results[0] = test_results[0] + 1 else: testing_helper.print_colored(" *** FAILED the above test. ***", color='red') test_results[1] = test_results[1] + 1 # SUMMARY of test results: print_summary_of_test_results(test_results)
def print_function_call_of_test(arguments, test_results, format_string): testing_helper.print_function_call_of_test(arguments, test_results, format_string)