【发布时间】:2020-10-22 17:16:20
【问题描述】:
我是单元测试的新手,我必须添加一个单元测试类来解决问题。问题是在这里找到的https://practice.geeksforgeeks.org/problems/penalty-shooters/0#,我的代码如下。我无法弄清楚如何使用用户输入进行单元测试。
T = int(input())
for x in range(T):
# Allows us to input and apply method to all iterables in a | no. of tests \n x_energy y_energy z_energy | format. T = number of tests, x is Lohia energy, y is Gosu energy and z is Goalkeeper energy
x, y, z = list(map(int, input().split(" ")))
Goal_Lohia, Goal_Gosu = 0, 0
# Session ends when goalkeepers energy decrements to 1
while z > 1:
# Goalkeepers energy in this case is a factor of both strikers' energy, so both score.
if x % z == 0 and y%z == 0:
x = x - 1
Goal_Lohia = Goal_Lohia + 1
y = y - 1
Goal_Gosu = Goal_Gosu + 1
# In this case, the goalkeepers energy is only a factor of Lohia's. Note Lohia goes first as the problem states.
elif x % z == 0:
x = x - 1
Goal_Lohia = Goal_Lohia + 1
# And in this case, it is only a factor of Gosu's
elif y % z == 0:
y = y - 1
Goal_Gosu = Goal_Gosu + 1
# If goalkeepers energy is a factor of neither Gosu nor Lohia, the goalkeeper will save (no goal scored) and will lose energy.
else:
z = z - 1
print(Goal_Lohia, Goal_Gosu)
非常感谢!
【问题讨论】:
-
欢迎来到 SO!您是否使用 unittest 作为您的框架?您是否编写了任何样板来设置您可以共享的测试作为起点并准确指出您卡在哪里? This 可能会有所帮助,并且有 pyunit 和 unittest 的信息...
-
嘿。这对你有帮助吗?我只是回去检查我发布的答案,看看我是否可以提供更多帮助,或者我是否可以弄清楚为什么我的答案没有被提出问题的人接受或赞成。
标签: python