Python: testing
Published in firmit.wordpress.com - 268 d 19 h ago
I am impressed! When writing the header of a function, why not simply write an example and automatically test the function?
#!/usr/bin/env python
import doctest
def fact(n, stop=1, r=1):
""" An iterative factorial function.
n! = n*(n-1)*(n-2)*..*(n-(n-stop-1))*r
stop fact(5,3)= 5*4
r fact(5,3,10)=5*4*10
>>> fact(5,3,10)
200
>>> fact(4)
24
"""
while n > stop :
r *= n
n -= 1
return r
def main():
doctest.testmod()
return 0
if __name__ == '__main__': main()
More here: http://docs.python.org/tutorial/stdlib.html#quality-control
... read more >>> firmit.wordpress.comSimilar entries
- status update on python scripting support
- Calling a C-Library from within Python
- Python 3.0 release
- Python - Still Getting started
- Python lernen #2
- Python 3.0 - a step forward?
- xmlrpc ด้วย python บน apache
- Disponible Python 3.0
- Tutorial Python II
- python class for looking at the connected machines on the network.
