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()
参考文献:
① https://www.liaoxuefeng.com/wiki/897692888725344/923056208268256
② Https://blog.csdn.net/u012084802/article/details/79481254
③ https://www.cnblogs.com/springionic/p/10711796.html
④ https://docs.Python.org/2/library/profile.html
⑤ https://blog.csdn.net/asukasmallriver/article/details/74356771