-
find
preconditions, postconditions, and tests - 5 pts -
power
implementation and tests - 5 pts
Create a module named unit_test.py
. You will write all
of your code in
this module.
Your task is to document and test some functions, then build and test another function.
find
Copy
the find
function from exercise 7.2.12. Write
documentation for it,
including
preconditions and postconditions. Add assert
statements
to enforce those conditions.
Then, write a function named test_find
that tests the
given find
function. Make sure
to write tests for
common cases, boundary cases, and edge cases.
power
power
function:def power(base, exp):
'''
power calculates b to the power of exp without using
the math module or the ** operator, and returns the result.
This function adheres to the interpretation that
0 to the 0 power is 1.
Preconditions:
base is an integer
exp is a non-negative integer
Postconditions:
returns an integer that is the calculation of base to the exp power
'''
Write a function test_power
that will test common cases, boundary cases, and edge cases.
Then, implement the power
function, writing assert
statements to enforce the given
preconditions and postconditions.
Make sure that you do not use ** or the math
module.
If you want to test that an assertion fails when the function is given invalid input, use code similar to the following:
try:
power(1, -1)
except AssertionError:
print("Assertion fails as expected")
Please style your code per section 3.4 of the textbook.
Submit one file, unit_test.py
,
through the online turnin form.
find
preconditions, postconditions, and tests - 5 pts
power
implementation and tests - 5 pts
Created October 17, 2016
Last revisedOctober 26, 2016, 01:38:16 PM PDT
This work is licensed under a Creative
Commons Attribution-Noncommercial-Share Alike 3.0 United States License.