-
Notifications
You must be signed in to change notification settings - Fork 0
/
unitTest.py
28 lines (23 loc) · 988 Bytes
/
unitTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#coding=utf-8
__metaclass__ = type
import unittest, my_math
from subprocess import Popen, PIPE
class ProductTestCase(unittest.TestCase):
def testWithPylint(self):
cmd = 'pylint -rn {0}'.format('my_math')
result = Popen(cmd, stdout = PIPE, stderr = PIPE)
self.assertEqual(result.stdout.read(), '')
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 failed')
def testFloats(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 failed')
if __name__ == '__main__':
unittest.main() #unittest.main函数负责运行测试.它会实例化所有TestCase的子类,运行所有名字以test开头的方法.