5

ペアワイズ テストを試みており、Python ベースのペアワイズ テスト ツールが必要でした。私はすでに AllPairs(http://pypi.python.org/pypi/AllPairs/2.0.1) を試しました。列に 10 個のエントリを指定するとバグが発生します。現在、Microsoft PICT を使用してペアごとの組み合わせを生成しています。

大きな配列のペアごとの組み合わせを生成する Python のツールはありますか?

これを与えるとAllPairsのバグ

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 ]
             ]

出力は

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

このため

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 ]
             ]

出力は

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

より大きな配列では正しく機能しないと思います。

4

4 に答える 4

3

このようなものはどうですか?

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)

使用法(parameters質問で定義したリストを使用):

>>> pairs = list(pairwiseGen(*parameters))
>>> len(pairs)
846

まだ最適化の余地があると思います (上記のジェネレーターは予想よりもわずかに多くの結果をもたらしました) が、デカルト積を使用するよりもはるかに短いことに同意すると思います。

>>> all_possible = list(product(*parameters))
>>> len(all_possible)
60480
于 2012-06-09T05:11:52.483 に答える
1

MS pict 実装のラッパーを作成しました。これは役に立つかもしれません。明らかに依存関係がありますが、ホイールの再作成を節約できます。

import os
import tempfile
import subprocess


def all_pairs(*sequence):
    """
    Calculate the all pairs testing sequence from the Microsoft PICT all pairs application
    that is compiled from: https://github.com/Microsoft/pict

    >>> Type = ['Single', 'Span', 'Stripe', 'Mirror', 'RAID-5']
    >>> Size = [10, 100, 500, 1000, 5000, 10000, 40000]
    >>> Format_method = ['Quick', 'Slow']
    >>> File_system = ['FAT', 'FAT32', 'NTFS']
    >>> Cluster_size = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
    >>> Compression = ['On', 'Off']
    >>> combinations = all_pairs(Type, Size, Format_method, File_system, Cluster_size, Compression)
    >>> assert len(combinations) == 56
    """
    exe = '/opt/pict/bin/pict'
    assert os.path.exists(exe), 'Make sure you have install the PICT executable to: {}'.format(exe)
    assert len(sequence) > 0
    for s in sequence:
        assert isinstance(s, list)
        assert len(s) > 0

    # create input file
    lines = list()
    for i, s in enumerate(sequence):
        seq = ', '.join([str(r) for r in range(len(s))])
        new_line = '{}: {}'.format(i, seq)
        lines.append(new_line)

    with tempfile.NamedTemporaryFile(mode='w') as tmp:
        tmp.write(os.linesep.join(lines))
        tmp.flush()
        result = subprocess.check_output([exe, tmp.name])

    options = list()
    for line in result.split(os.linesep)[1:]:  # skip the header
        if len(line) == 0:
            continue
        indices = [int(i) for i in line.split('\t')]
        options.append([s[i] for s, i in zip(sequence, indices)])
    return options
于 2016-08-17T10:38:05.140 に答える