I have a sorting algorithm that seems to work fine but I would like to test it more with random samples. So to test it, I'm trying to generate random arrays with hypothesis in Python, I would like the arrays to be of various lengths and contain any random numbers. However hypothesis seem to be stuck on filling the arrays with the digit "1" only
Here is my code:
def mysorting_function function(ArrToSort):
#...
@given (
i= lists( integers(min_value=1) )
)
def test_partition(i):
#sort the random array i
mysorting_function(i)
#run the test to check if it is sorted
for i in range( len(i)-1):
assert a[i]<= a[i+1]
However when I print the output of the test, the samples that hypothesis generates are:
[1]
[1]
[1, 1]
[1, 1, 1]
[1, 1, 1, 1]
[1, 1, 1, 1, 1]
[1]
[1]
If I remove the min_value=1
I get array of 0, if I put min_value=2
, I get arrays with nothing but 2! which is weird, I want these values to be random.
Can someone please help me and explain what I'm doing wrong? is there a random seed that I need to initialize? A missing parameter? something wrong with my imports?
Thanks in advance
p.s: I know there are other ways to generate the random list, but I want to get to work with Hypothesis please :)
Run using pytest tmp.py -s
I am probably doing something wrong with the printing process, but as you can see that different outputs are generated by the hypothesis library