How would you test a function which could lead to a random choice. For instance:
def getMaxIndices(lst):
'''
:lst: list of int
Return indices of max value. If max value appears more than once,
we chose one of its indices randomly.
'''
index_lst = [(i, j) for i in enumerate(lst)]
shuffle(index_lst)
index_lst.sort(key=lambda x: x[1])
max_index = index_lst.pop()[0]
return max_index
I can't find a satisfying way to test it.
How would you do ?
Aucun commentaire:
Enregistrer un commentaire