浅析软件测试过程--实现方法对比-创新互联
两种不同的实现过程:算法-1,算法-2。
创新互联主营下冶网站建设的网络公司,主营网站建设方案,手机APP定制开发,下冶h5微信平台小程序开发搭建,下冶网站营销推广欢迎下冶等地区企业咨询对比不同的算法实现的逻辑和效率差异,体会不同实现过程对测试方法、过程的影响。
软件黑盒测试和白盒测试是相互融合、相互补充的两种方法,完全相同的外部结果,其实现却有着不同的方法和效率。
不同的设计思想、构造和实现方法,应有不同的测试策略和方法与之相对应。
软件测试不仅要发现错误,更要预防错误,理解和分析是实现预测的基本能力和方法。
############################## 算法 - 1 ###################################
###########################################################################
# -*- coding: utf-8 -*-
#********************************************************************
# Copyright (c) 2014,LeiXun Studio
# All Rights Reserved.
#
# File Name: NumCompare.py
# Summary: Compare num W with num X
#
# Question:
# 带通配符的数: 给定一个带通配符问号的数W,问号可以代表任意一个一位数字。再给定一个整数X,和W具有同样的长度。问有多少个整数符合W的形式并且比X大?
# 输入格式 多组数据,每组数据两行,第一行是W,第二行是X,它们长度相同。在[1..10]之间. 输出格式 每行一个整数表示结果。
# 输入样例 36?1?8 236428 8?3 910 ? 5 输出样例 100 0 4
#
# @Version: 1.0
# @Author: Roy
# @Date: 04/25/2014
#
# @Update Version: 1.0
# @Author:
# @End Date:
#*********************************************************************
import re
#global ch
#ch = True
def checknum(num,n1):
try:
if num[0] == '0':
print 'The %s is wrong, please input again.' %num
return 0
for i in range(0,len(num)):
if (num[i] == n1) or (int(num[i]) in range(10)):
continue
else:
print 'The %s is wrong, please input again.' %num
return 0
return num
except:
print 'Inputting is wrong...'
return 0
def getnum():
#global ch
T = []
while 1:
W = raw_input('Please input the number W: ')
if W == 'quit':
#ch = False
break
return T
elif checknum(W,'?') == 0:
#ch = False
break
return 0
else:
T.append(W)
X = raw_input('Please input the number X: ')
if len(W) != len(X):
print 'Inputting is wrong, length not equal.'
#ch = False
break
return 0
elif checknum(X,'0') == 0:
#ch = False
break
return 0
else:
T.append(X)
return T
def comnum(w,x):
l = len(w)
c = w.count('?')
cn = 0
s = 0
tt = [t.start() for t in re.finditer('\?',w)] #'?' position in W
for i in range(len(tt)):
if i == 0:
s = 0
else:
s = tt[i - 1] + 1
if tt[i] == 0:
cn = cn + (9-int(x[i]))*(10**(c-i-1))
elif s == tt[i]:
cn = cn + (9-int(x[i]))*(10**(c-i-1))
elif int(w[s:tt[i]]) >= int(x[s:tt[i]]):
cn = cn + 10**(c-i)
else:
return cn
return cn
if __name__ == "__main__":
import doctest, NumCompare
G = getnum()
if len(G) != 0:
for i in range(len(G)//2):
print comnum(G[i*2],G[i*2+1])
doctest.testmod(NumCompare)
###########################################################################
############################## 算法 - 2 ###################################
###########################################################################
# -*- coding: utf-8 -*-
#********************************************************************
# Copyright (c) 2014,LeiXun Studio
# All Rights Reserved.
#
# File Name: NumCompare.py
# Summary: Compare num W with num X
#
# Question:
# 带通配符的数: 给定一个带通配符问号的数W,问号可以代表任意一个一位数字。再给定一个整数X,和W具有同样的长度。问有多少个整数符合W的形式并且比X大?
# 输入格式 多组数据,每组数据两行,第一行是W,第二行是X,它们长度相同。在[1..10]之间. 输出格式 每行一个整数表示结果。
# 输入样例 36?1?8 236428 8?3 910 ? 5 输出样例 100 0 4
#
# @Version: 1.0
# @Author: Roy
# @Date: 03/25/2014
#
# @Update Version: 1.0
# @Author:
# @End Date:
#*********************************************************************
global T,l,c,cn,tc,W,X,p, ml
T = [] #accepte and store varable input
W = [] #get W from T
X = [] #get X from T
l = 0 #length of inputting w
c = 0 #count of '?' in W
tc = 0 #element's position of W
cn = 0 #question's result
p = 0 #position of first '?' for W
def NumCopare(w,x):
global l,c,cn,tc,W,X,T,p, ml
if w != '?' and int(w) not in range(10):
print ("W3 is incorrect,Please input correct num!\n")
return
if int(x) not in range(10):
print ("X4 is incorrect,Please input correct num!\n")
return
if tc < l :
if w != '?' and c != 0:
if int(w) > int(x):
t = int(w) - int(x)
cn = 10**c*t
#cn = 10**c
return cn
elif int(w) < int(x):
cn = cn + 0
return cn
elif int(w) == int(x):
tc = tc + 1
NumCopare(W[tc],X[tc])
else:
if w == '?':
cn1 = 0
cn2 = 0
t = 9 - int(x)
cn1 = 10**(c-1)*t
tc = tc + 1
c = c -1
if tc < l-1:
cn2 = NumCopare(W[tc],X[tc])
cn = cn1 + cn2
return cn
def getnum():
global T
while 1:
# print("*********************** Compare input number ************************")
# ww = raw_input('Please input the number W: ')
ww = raw_input()
wl = len(ww)
wc = ww.count('?')
if ww == "quit":
break
elif wc == 0:
print("W1 is incorrect,Please input correct num!\n")
else: #judge inputting correction for W
for i in range(0,len(W)-1):
try:
int(ww[i])
except(ValueError):
if ww[i] != '?':
print ("W2 is incorrect,Please input correct num!\n")
return
T.append(ww)
# xx = raw_input('Please input the number X: ')
xx = raw_input()
xl = len(xx)
if xl < wl:
print ("X1 is incorrect,Please input correct num!\n")
break
elif xx.count('?') > 0:
print ("X2 is incorrect,Please input correct num!\n")
return
elif xx[0] == '0' and xl == wl and xl > 1:
print ("X3 is incorrect,Please input correct num!\n")
return
else:#judge inputting correction for xx
try:
int(xx)
except(ValueError):
print ("X4 is incorrect,Please input correct num!\n")
return
T.append(xx)
return T
def getcount(TT):
global l,c,W,X,T,p,cn, tc
if TT != None:
ll = len(TT)
else:
return
for i in range(ll//2):
tc = 0
cn = 0
W = []
W = TT[i*2]
l = len(W)
c = W.count('?')
p = W.find('?')
X = []
X = TT[i*2+1]
NumCopare(W[0],X[0])
#print "There is " + str(cn) + " W greater than X.\n"
print str(cn)
#print getnum()
if __name__ == "__main__":
import doctest, NumCompare
getcount(getnum())
doctest.testmod(NumCompare)
###########################################################################
名称栏目:浅析软件测试过程--实现方法对比-创新互联
网页地址:http://ybzwz.com/article/phjjh.html