[<<][python][>>][..]
Sat Mar 29 10:02:45 EDT 2014

DIY property based testing

Interesting problem.

Is a type a sequence (generator) of values or a generator of a
sequence (generator) of values?

The extra indirection seems like a good idea from the concept level,
but because everything is random, it doesn't seem that it really
matters.

So this seems to work:

def a_range(min, max):
    while True:
        yield random.randint(min, max)

a_byte = a_range(0, 255)

def a_list(el_type, min=0, max=10):
    while True:
        len = random.randint(min, max)
        yield [el_type.__next__() for i in range(len)]

def a_tuple(*el_types):
    while True:
        yield tuple([t.__next__() for t in el_types])

def forall(n, f, *arg_types):
    for i,args in zip(range(n), a_tuple(*arg_types)):
        f(*args)




[Reply][About]
[<<][python][>>][..]