コード例 #1
0
def test_construct_orthogonal_array():
    # check for valid inputs
    with pytest.raises(ValueError):
        _construct_orthogonal_array(3, strength=-1)
    with pytest.raises(ValueError):
        _construct_orthogonal_array(3, strength=4)
    with pytest.raises(ValueError):
        _construct_orthogonal_array(3, strength=100)
コード例 #2
0
def test_orthogonal_array():
    def bit_array_to_int(bit_array):
        output = 0
        for bit in bit_array:
            output = (output << 1) | bit
        return output

    def check_random_columns(oa, strength):
        num_q = oa.shape[1]
        num_cols = min(num_q, strength)
        column_idxs = random.sample(range(num_q), num_cols)
        occurences = {entry: 0 for entry in range(2**num_cols)}
        for row in oa[:, column_idxs]:
            occurences[bit_array_to_int(row)] += 1
        assert all([count == occurences[0] for count in occurences.values()])

    for strength in [0, 1, 2, 3]:
        for num_q in range(1, 64):
            oa = _construct_orthogonal_array(num_q, strength=strength)
            for _ in range(10):
                check_random_columns(oa, strength)