Python????????????unittestpyUnit
???????????? ???????[ 2014/4/18 11:30:11 ] ??????????????? Python
???????Pyunit??????????
'''''
Created on 2014-4-15
@author: Administrator
'''
import unittest??my_math
class Test(unittest.TestCase):
def testIntegers(self):
for x in xrange(-10??10):
for y in xrange(-10??10):
p = my_math.product(x??y)
self.failUnless(p == x*y??'Integer multiplication faild')
def testFloat(self):
for x in xrange(-10??10):
for y in xrange(-10??10):
x = x/10.0
y = y/10.0
p = my_math.product(x??y)
self.failUnless(p == x*y??'Float multiplication faild')
if __name__ == "__main__":
#import sys;sys.argv = [''?? 'Test.testName']
unittest.main()
my_math.py
'''''
Created on 2014-4-15
@author: Administrator
'''
def square(x):
'''''
Squares a number and return the result.
>>>square(2)
4
>>>square(3)
9
'''
return x*x
def product(x??y):
if x == 7 and y ==9:
return 'bug'
else:
return x * y
#return x*y
'''''
if __name__ == '__main__':
import doctest?? my_math
doctest.testmod(my_math)
'''
????unittest.main???????????в?????????????????TestCase????????????????????test??????????
????????????????setUp??tearDown?????????????????????????????????????С?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11