Doctest: The Easiest Testing Tool(Chapter 2 of Python Testing Beginner's Guide)
时间:2010-11-28 来源:Ray Z
testable
1 def testable(x):
2 r"""
3 The testable functin returns the square root of its parameter, or 3, whichever is larger.
4 >>> testable(7)
5 3.0
6 >>> testable(16)
7 4.0
8 >>> testable(9)
9 3.0
10 >>> testable(10) == 10 ** 0.5
11 True
12 """
13 if x < 9:
14 return 3.0
15 return x ** 0.5
2 r"""
3 The testable functin returns the square root of its parameter, or 3, whichever is larger.
4 >>> testable(7)
5 3.0
6 >>> testable(16)
7 4.0
8 >>> testable(9)
9 3.0
10 >>> testable(10) == 10 ** 0.5
11 True
12 """
13 if x < 9:
14 return 3.0
15 return x ** 0.5
相关阅读 更多 +