[Tutor] How to test a function which runs a passed in function twice?

boB Stepp robertvstepp at gmail.com
Sun Oct 2 18:47:51 EDT 2016


In exercise 3.2 of Downey's "Think Python 2" he has a function:

def do_twice(f):
    f()
    f()

As you know, I am trying to learn testing/TDD while doing these
exercises.  How do I test such a *general* function?  Should I create
a variety of arbitrary functions in my test file, call the do_twice
function with each of these made up functions and see if I get the
expected results?

I can see doing this, but since the function to be tested is so
general in nature, I do not see how I can feel confident that I am
adequately testing it.  I cannot even conceive of what might be edge
cases for this function.  Something exploring the limits of Python's
functionality?

-- 
boB


More information about the Tutor mailing list