1

I am trying to test this function

def print_board(M):
    for i in range (M.shape[0]):
        line=''
        for j in range (M.shape[1]):
           line+=str(int(M[i,j]))
        print(line)

I created a new file to test it and imported my file and the function array but I am not too sure on how I can test it since I don't return it, I tried this :

assert(print_board(array([[1,1,1],[0,0,0],[1,1,1]],dtype='bool')) == '''111 000 111''')

but got

AssertionError

depperm
  • 10,606
  • 4
  • 43
  • 67
Kabou
  • 53
  • 6
  • His function is quite too difficult for me to understand the answers that was given to him for me to apply it to myself, sorry. – Kabou Sep 22 '16 at 19:44
  • Your guess is correct; since print_board has no `return` statement, the return value is Python's `None' value. – CAB Sep 22 '16 at 19:48

1 Answers1

-1

What you could do is redirect Python standard output (where print sends it) to a string, and then compare that string.

See this question for an explanation of how to do that.

Community
  • 1
  • 1
CAB
  • 1,106
  • 9
  • 23