[英]Issues with unit testing
I want to test a function, but I am definitely struggling at this one.我想测试一个 function,但我肯定在这方面苦苦挣扎。 The function loops through boards last row if NO_PLayer is valid location.
如果 NO_PLayer 是有效位置,则 function 将遍历板的最后一行。
def validLocations(board):
validLocationsArr = []
column = 0
row = 0
while column < 6:
if (board[5][column] == NO_PLAYER):
validLocationsArr.append(column)
column += 1
return validLocationsArr
I worked on it, and tried it, but:我研究了它,并尝试了它,但是:
def test_validLocations(self):
from agents.common import validLocations
ret = validLocations(board)
assert np.all(ret == NO_PLAYER)
Can anyone help me?谁能帮我? Many thanks in advance!
提前谢谢了!
Wihout further info from the OP, I think the problem is in the last assert
statement.如果没有来自 OP 的进一步信息,我认为问题出在最后一个
assert
语句中。
Use Python's all()
instead of Numpy's np.all()
:使用Python 的
all()
而不是 Numpy 的np.all()
:
ret = validLocations(board) # as before
assert all(loc == NO_PLAYER for loc in ret)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.