I am trying pairwise testing and wanted Python based pairwise testing tool. I already tried AllPairs(http://pypi.python.org/pypi/AllPairs/2.0.1). It has bug when I give 10 entries in a Column. Currently using Microsoft PICT to generate pairwise combination.
Is there any tool in Python that generates pairwise combinations for large arrays?
Bug in AllPairs If I give this
parameters = [ [ "Brand X", "Brand Y","Brand A","Brand B","Brand C","Brand D" ]
, [ "98", "NT", "2000", "XP"]
, [ "Internal", "Modem","A","B","C","D","E","F","G","H","I","J","K","L","M" ]
, [ "Salaried", "Hourly", "Part-Time", "Contr.","AA","BB","CC","DD","EE","FF","GG","HH","II" ]
, [ 6, 10, 15, 30, 60, 70, 80, 90, 100, 110, 120, 130, 140 ]
]
Output is
Brand X count is 16
Brand Y count is 122
Brand A count is 16
Brand B count is 16
Brand C count is 16
Brand D count is 15
for this
parameters = [ [ "Brand X", "Brand Y","Brand A","Brand B","Brand C","Brand D" ]
, [ "98", "NT", "2000", "XP"]
, [ "Internal", "Modem" ]
, [ "Salaried", "Hourly", "Part-Time", "Contr." ]
, [ 6, 10, 15, 30, 60 ]
]
output is
Brand X count is 5
Brand Y count is 5
Brand A count is 5
Brand B count is 5
Brand C count is 5
Brand D count is 6
I think, it is not correct working for larger array.
How about something like this?
from itertools import chain, combinations, product
def pairwiseGen(*sequences):
unseen = set(chain.from_iterable(product(*i) for i in combinations(sequences, 2)))
for path in product(*sequences):
common_pairs = set(combinations(path, 2)) & unseen
if common_pairs:
yield path
unseen.difference_update(common_pairs)
Usage (using the parameters
list you defined in your question):
>>> pairs = list(pairwiseGen(*parameters))
>>> len(pairs)
846
I think there is still some room for optimization (the above generator yielded slightly more results than were expected), but I think you'll agree that it's much shorter than using the cartesian product:
>>> all_possible = list(product(*parameters))
>>> len(all_possible)
60480
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With