python 程序小測試html
對以前寫的程序作簡單的小測試 ...python
1 # -*- encoding:utf-8 -*- 2 ''' 3 對所寫程序作簡單的測試 4 @author: bpf 5 ''' 6 def GameOver(N, scoreA, scoreB): 7 ''' 8 function: 定義一局排球比賽的結束條件 9 N: 表明當前局次(第五局爲決勝局) 10 前四局,每一個隊只有在贏得至少25分,且同時超過對方2分時才勝一局 11 第五局,每一個隊只有在贏得至少15分,且同時超過對方2分時才勝一局 12 return: 若比賽結束的條件成立返回真,不然爲假 15 13 ''' 14 if N <= 4: 15 return (scoreA>=25 and abs(scoreA-scoreB)>=2) or (scoreB>=25 and abs(scoreA-scoreB)>=2) 16 else: 17 return (scoreA>=15 and abs(scoreA-scoreB)>=2) or (scoreB>=15 and abs(scoreA-scoreB)>=2) 18 19 def Test(): 20 try: 21 N = [1, 2, 3, 4, 5, 5, 5] 22 scoreA = [13, 24, 26, 24, 14, 17, 15] 23 scoreB = [25, 25, 25, 0, 16, 16, 0] 24 result = ["True", "False", "False", "False", "True", "False", "True"] 25 for i in range(0, 7): 26 if str(GameOver(N[i], scoreA[i], scoreB[i])) == result[i]: 27 print("Test {}: Right Result!".format(i+1)) 28 else: 29 print("Test {}: Error Result!".format(i+1)) 30 except Exception as e: 31 print("Error:", e) 2 33 Test()
參考文獻: spring
① https://www.liaoxuefeng.com/wiki/897692888725344/923056208268256ionic
② http://www.javashuo.com/article/p-hlgduxtd-ng.html測試
③ http://www.javashuo.com/article/p-rnvftkri-bs.htmlspa
④ https://docs.python.org/2/library/profile.html.net
⑤ https://blog.csdn.net/asukasmallriver/article/details/74356771code