Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate test data for my Python script?

Tags:

python

A 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 do I generate a series of test values for this function ? for instance I want to send a 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 my clarify. what I wanted to ask how I can do x =[a,b] generate different values for a,b


1 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 )
like image 105
bayda Avatar answered Sep 07 '25 15:09

bayda