???????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?????????????????????????????????????С?