#!/usr/local/bin/python -t
# -*- coding: utf8 -*- 
'''A demonstration of W0631
W: 39:tests: Using possibly undefined loop variable '_i'
'''

if __name__ == "__main__":
    def tests(*varg):
        '''Run the tests with given or random data.
        Numerical parameters can be given in the command line for tests.
        Three least significant bits of the first parameter:
        LSB: verbose.
        LSB+1: run a test for Int().
        LSB+2: run a test for Float().
        If exactly 2 parameters are given, the second is the length of a 
        randomly generated test sequence.
        If more than 2 parameters are given, the second and further parameters
        are used as the test sequence (two times if both tests are run).
        No parameters is equivalent to giving two pamaters 6 32 (i.e. both two
        tests not verbose with sequences of 32 random numbers each).
        '''
        import random

        varg = varg[0]
        debug = 0
        length = 32
        if len(varg) > 0:
            debug = int(varg[0])
        if len(varg) == 2:
            length = int(varg[1])
        if debug & 2:
            if len(varg) > 2:
                arr = [_i for _i in varg[1:]]
            else:
                arr = [int(random.uniform(0, 20)) for _ in range(length)]
            print arr
        if debug & 4:
            if len(varg) > 2:
                arr = [_i for _i in varg[1:]]
            else:
                arr = [float(random.uniform(0, 1)) for _ in range(length)]
            print arr

    import sys
    tests(sys.argv[1:])
