开发者

Getting all possible value combinations

开发者 https://www.devze.com 2023-01-29 10:39 出处:网络
For an automatic test thing, I have a class with ~15 parameters. I want to automatically generate instances of the class for every possible value combination. For instance, if the class was defined li

For an automatic test thing, I have a class with ~15 parameters. I want to automatically generate instances of the class for every possible value combination. For instance, if the class was defined like so:

class meep():
    def __init__(self):
        self.par1 = 0 # can be in range {0-3}
        self.par2 = 1 # can be in range {1-2}
        self.par3 = a # can be in range {a-c}

What is the most efficient to get instances of it with all possible value combinations? (IE

inst1=(par1=0,par2=1,par3=a), 
in开发者_StackOverflow社区st2=(par1=0,par2=1,par3=b), 
inst3=(par1=0,par2=1,par3=c),
inst4=(par1=1,par2=1,par3=a), 
inst5=(par1=1,par2=1,par3=b), 
inst6=(par1=1,par2=1,par3=c),

etc.)


itertools.product()

0

精彩评论

暂无评论...
验证码 换一张
取 消