0

I want to test a function, but I am definitely struggling at this one. The function loops through boards last row if NO_PLayer is valid location.

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!

Thomas
  • 174,939
  • 50
  • 355
  • 478
Lissa
  • 1
  • Could you provide what value `board` is in the test function. And what is `NO_PLAYER` set to? `object()`? – aneroid Feb 22 '21 at 15:11

1 Answers1

0

Wihout further info from the OP, I think the problem is in the last assert statement.

Use Python's all() instead of Numpy's np.all():

ret = validLocations(board)  # as before
assert all(loc == NO_PLAYER for loc in ret)
aneroid
  • 12,983
  • 3
  • 36
  • 66