# 导航

### 测试框架设计&模拟测试数据

• 加减乘除功能测试(支持整数,小数,分数,及混合)
• 非法输入反馈测试
• 除0错误反馈测试

• #### 加减乘除功能测试:

	def test_plus(self):
ques = ['1+2','2.7+1','2.5+3.6','2/3+3/4','2/3+3']
key = ['3','3.7','6.1','17/12','11/3']
for i in range(4):
test = str(Calc(ques[i]))
self.assertEqual(test, key[i])

def test_sub(self):
ques = ['4-3','2.7-1','3.5-2.6','3/4-2/3','3-2/3']
key = ['1','1.7','0.9','1/12','7/3']
for i in range(4):
test = str(Calc(ques[i]))
self.assertEqual(test, key[i])

def test_mult(self):
ques = ['4*3','2.7*1','3.5*2.6','3/4*2/3','2/3*3']
key = ['12','2.7','9.1','1/2','2']
for i in range(4):
test = str(Calc(ques[i]))
self.assertEqual(test, key[i])

def test_div(self):
ques = ['4/3','2.7/1','3.5/0.7','3/4/2/3','2/3/3']
key = ['4/3','2.7','5.0','9/8','2/9']
for i in range(4):
test = str(Calc(ques[i]))
self.assertEqual(test, key[i])


• #### 非法输入反馈测试:

	def test_error_arg(self):
ques = ['1++2','+1+2','.1.5*2','5-6+']
for i in range(4):
test = str(Calc(ques[i]))
self.assertEqual(test, 'error')


    def __calc_main(self):
reg1 = r'(\d+(\.\d+)?)([-*/\+]{1})(\d+(\.\d+)?)'
reg2 = r'(\d+(/\d+)?)([-*/\+]{1})(\d+(/\d+)?)'
QuesReg1 = re.compile(reg1)
QuesReg2 = re.compile(reg2)
result1 = QuesReg1.match(self.ques_str)
result2 = QuesReg2.match(self.ques_str)
...
if result1 and result1.group(0)==self.ques_str:
...
elif result2 and result2.group(0)==self.ques_str:
...
else:
return 'error'


• #### 除0错误反馈测试:

	def test_ZeroDivisionError(self):
ques = ['5/0','1.5/0','1/5/0']
for i in range(3):
test = str(Calc(ques[i]))
self.assertEqual(test, 'zero_error')


	def __calcbox(self,a,b,sign_index):
try:
if type(a)==float or type(b)==float:
cal_result =[a+b,a-b,a*b,a/b]
else:
cal_result =[a+b,a-b,a*b,Fraction(a,b)]
return cal_result[sign_index]
except ZeroDivisionError:
return 'zero_error'


• #### 测试过程遇到的问题以及解决方案:

整个测试过程并没有遇到什么特别大的问题,算是比较顺利
可能是因为计算模块在写的时候已经经过了数次排查测试,功能已经很完善

### PSP

posted on 2017-03-24 22:16  Jahowz  阅读(191)  评论(5编辑  收藏  举报