Download both files at the left and put them in the same directory (smart idea: make a directory for this assignment) Save time by right-clicking on the links and using Save Link As.
You will import the testing apparatus into your code.
Here is my test module
############################################################
# Author: Morrison
# Date created: 2021-08-30
# Date last modified: 2021-09-15
# rt Module
# Usage is as follows for non-floating point return values:
# run_test(function, expected_output, [arg1, arg2, ....])
# Usage for floating-point return values:
# run_test(function, expected_output, [arg1, arg2, ....])
################# DO NOT CHANGE THIS CODE ###################
TOLERANCE = 1e-6
def close_enough(x,y):
return abs(x - y) < TOLERANCE
def run_test(function, expected, args):
if function(*args) == expected:
print(f"PASS for case {args} for function {function.__name__}")
else:
print(f"FAIL because {function.__name__}({args}) != {expected}")
def run_test_float(function, expected, args):
if close_enough(function(*args), expected):
print(f"PASS for case {args} for function {function.__name__}")
else:
print(f"FAIL because {function.__name__}({args}) != {expected}")
Here is the shell code. It runs out of the box.
from rt import close_enough, run_test, run_test_float
def power_rec(base, exp):
"""prec: base is a number, exp is an integer
postc: retuerns base**exp using a recursive version of the
divide and conquer power algorithm"""
return 1
def power_iter(x, b):
"""prec:se is a number, exp is an integer
postc: returns base**exp using an itearative version of the
divide and conquer power algorithm"""
return 1
def main():
##run tests here
run_test(power_rec, 1024, [2, 10])
main()