溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

淺析軟件測(cè)試過程--實(shí)現(xiàn)方法對(duì)比

發(fā)布時(shí)間:2020-07-06 12:37:23 來源:網(wǎng)絡(luò) 閱讀:489 作者:rolei 欄目:軟件技術(shù)

兩種不同的實(shí)現(xiàn)過程:算法-1,算法-2。

 

對(duì)比不同的算法實(shí)現(xiàn)的邏輯和效率差異,體會(huì)不同實(shí)現(xiàn)過程對(duì)測(cè)試方法、過程的影響。

 

軟件黑盒測(cè)試和白盒測(cè)試是相互融合、相互補(bǔ)充的兩種方法,完全相同的外部結(jié)果,其實(shí)現(xiàn)卻有著不同的方法和效率。

不同的設(shè)計(jì)思想、構(gòu)造和實(shí)現(xiàn)方法,應(yīng)有不同的測(cè)試策略和方法與之相對(duì)應(yīng)。

軟件測(cè)試不僅要發(fā)現(xiàn)錯(cuò)誤,更要預(yù)防錯(cuò)誤,理解和分析是實(shí)現(xiàn)預(yù)測(cè)的基本能力和方法。

 

############################## 算法 - 1 ###################################

###########################################################################

# -*- coding: utf-8 -*-

#********************************************************************
# Copyright (c) 2014,LeiXun Studio
# All Rights Reserved.
#
# File Name: NumCompare.py
# Summary: Compare num W with num X
#
# Question:
# 帶通配符的數(shù): 給定一個(gè)帶通配符問號(hào)的數(shù)W,問號(hào)可以代表任意一個(gè)一位數(shù)字。再給定一個(gè)整數(shù)X,和W具有同樣的長(zhǎng)度。問有多少個(gè)整數(shù)符合W的形式并且比X大?
# 輸入格式 多組數(shù)據(jù),每組數(shù)據(jù)兩行,第一行是W,第二行是X,它們長(zhǎng)度相同。在[1..10]之間. 輸出格式 每行一個(gè)整數(shù)表示結(jié)果。 
# 輸入樣例 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:
# 帶通配符的數(shù): 給定一個(gè)帶通配符問號(hào)的數(shù)W,問號(hào)可以代表任意一個(gè)一位數(shù)字。再給定一個(gè)整數(shù)X,和W具有同樣的長(zhǎng)度。問有多少個(gè)整數(shù)符合W的形式并且比X大?
# 輸入格式 多組數(shù)據(jù),每組數(shù)據(jù)兩行,第一行是W,第二行是X,它們長(zhǎng)度相同。在[1..10]之間. 輸出格式 每行一個(gè)整數(shù)表示結(jié)果。 
# 輸入樣例 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)

###########################################################################

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI