How to create test data for my Python script?

The equation takes values ​​in the following form:

   x = [0x02,0x00]  # which is later internally converted to in the called function to  0x300
   y = [0x01, 0xFF]
   z = [0x01, 0x0F]

How to create a series of test values ​​for this function? for example, I want to send 100 odd values ​​from a for loop

for i in range(0,300):
   # where a,b are derived for a range
   x = [a,b]

My question was a bit unclear, so please let me clarify. what i wanted to ask how can i do x =[a,b]generate different values ​​fora,b

+3
source share
2 answers

use generators:

def gen_xyz( max_iteration ):
    for i in xrange( 0, max_iteration ):
       # code which will generate next ( x, y, z )
       yield ( x, y, z ) 

for x, y, z in gen_xyz( 1000 ):
  f( x, y, z )
+3
source

Hex () function?

import random
for i in range(10):
    a1, a2 = random.randint(1,100), random.randint(1,100)
    x = [hex(a1), hex(a2)]
    print x

.. outputs something similar to.

['0x21', '0x4f']
['0x59', '0x5c']
['0x61', '0x40']
['0x57', '0x45']
['0x1a', '0x11']
['0x4c', '0x49']
['0x40', '0x1b']
['0x1f', '0x7']
['0x8', '0x2b']
['0x1e', '0x13']
+1
source

Source: https://habr.com/ru/post/1705228/


All Articles