コード例 #1
0
 def test_product_with_sum(self):
     verify_matrix_output_diversity(
         matrix.Sum(9, [
             mbs(10, range(6)),
             matrix.Product(
                 1, [mbs(1, range(2)),
                     mbs(2, range(5)),
                     mbs(4, range(4))]),
             matrix.Product(
                 8, [mbs(7, range(2)),
                     mbs(6, range(5)),
                     mbs(5, range(4))])
         ]))
コード例 #2
0
 def test_product_3_facets_2_prime_factors(self):
     verify_matrix_output_diversity(
         matrix.Product(1, [
             mbs(1, range(6)),
             mbs(2, range(2)),
             mbs(3, range(3)),
         ]))
コード例 #3
0
 def test_product_3_facets_2_prime_factors_one_larger(self):
     verify_matrix_output_diversity(
         matrix.Product(1, [
             mbs(1, range(2)),
             mbs(2, range(5)),
             mbs(4, range(4)),
         ]))
コード例 #4
0
def _build_matrix(path, mincyclicity=0, item=''):
    if os.path.basename(path)[0] == '.':
        return None
    if not os.path.exists(path):
        raise IOError('%s does not exist (abs %s)' %
                      (path, os.path.abspath(path)))
    if os.path.isfile(path):
        if path.endswith('.yaml'):
            return matrix.Base(item)
        return None
    if os.path.isdir(path):
        if path.endswith('.disable'):
            return None
        files = sorted(os.listdir(path))
        if len(files) == 0:
            return None
        if '+' in files:
            # concatenate items
            files.remove('+')
            submats = []
            for fn in sorted(files):
                submat = _build_matrix(os.path.join(path, fn), mincyclicity,
                                       fn)
                if submat is not None:
                    submats.append(submat)
            return matrix.Concat(item, submats)
        elif path.endswith('$') or '$' in files:
            # pick a random item -- make sure we don't pick any magic files
            if '$' in files:
                files.remove('$')
            if '%' in files:
                files.remove('%')
            submats = []
            for fn in sorted(files):
                submat = _build_matrix(os.path.join(path, fn), mincyclicity,
                                       fn)
                if submat is not None:
                    submats.append(submat)
            return matrix.PickRandom(item, submats)
        elif '%' in files:
            # convolve items
            files.remove('%')
            submats = []
            for fn in sorted(files):
                submat = _build_matrix(os.path.join(path, fn),
                                       mincyclicity=0,
                                       item=fn)
                if submat is not None:
                    submats.append(submat)
            mat = matrix.Product(item, submats)
            if mat and mat.cyclicity() < mincyclicity:
                mat = matrix.Cycle(
                    (mincyclicity + mat.cyclicity() - 1) / mat.cyclicity(),
                    mat)
            return mat
        else:
            # list items
            submats = []
            for fn in sorted(files):
                submat = _build_matrix(os.path.join(path, fn), mincyclicity,
                                       fn)
                if submat is None:
                    continue
                if submat.cyclicity() < mincyclicity:
                    submat = matrix.Cycle(
                        ((mincyclicity + submat.cyclicity() - 1) /
                         submat.cyclicity()), submat)
                submats.append(submat)
            return matrix.Sum(item, submats)
    assert False, "Invalid path %s seen in _build_matrix" % path
    return None
コード例 #5
0
 def test_product_simple(self):
     verify_matrix_output_diversity(
         matrix.Product(
             1, [mbs(1, range(6)), mbs(2, range(2))]))