簡體   English   中英

如何為我的 Python 腳本生成測試數據?

[英]How do I generate test data for my Python script?

等式采用以下形式的值:

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

如何為這個 function 生成一系列測試值? 例如,我想從 for 循環中發送 100 個奇數值

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

我的問題有點不清楚,所以請讓我澄清一下。 我想問我怎么做x =[a,b]a,b生成不同的值

使用生成器:

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 )

十六進制()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

..輸出類似於..的東西

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM