python 程序小测试

2023-03-15,,

python 程序小测试

对之前写的程序做简单的小测试 ...

 # -*- encoding:utf-8 -*-
'''
对所写程序做简单的测试
@author: bpf
'''
def GameOver(N, scoreA, scoreB):
'''
function: 定义一局排球比赛的结束条件
N: 代表当前局次(第五局为决胜局)
前四局,每个队只有在赢得至少25分,且同时超过对方2分时才胜一局
第五局,每个队只有在赢得至少15分,且同时超过对方2分时才胜一局
return: 若比赛结束的条件成立返回真,否则为假 15
'''
if N <= 4:
return (scoreA>=25 and abs(scoreA-scoreB)>=2) or (scoreB>=25 and abs(scoreA-scoreB)>=2)
else:
return (scoreA>=15 and abs(scoreA-scoreB)>=2) or (scoreB>=15 and abs(scoreA-scoreB)>=2) def Test():
try:
N = [1, 2, 3, 4, 5, 5, 5]
scoreA = [13, 24, 26, 24, 14, 17, 15]
scoreB = [25, 25, 25, 0, 16, 16, 0]
result = ["True", "False", "False", "False", "True", "False", "True"]
for i in range(0, 7):
if str(GameOver(N[i], scoreA[i], scoreB[i])) == result[i]:
print("Test {}: Right Result!".format(i+1))
else:
print("Test {}: Error Result!".format(i+1))
except Exception as e:
print("Error:", e)
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

python 程序小测试的相关教程结束。

《python 程序小测试.doc》

下载本文的Word格式文档,以方便收藏与打印。