Ejemplo n.º 1
0
def test_constraint_violation():
    are_constraints_violated = UniformCombinatoricSamplingStrategy._UniformCombinatoricSamplingStrategy__are_constraints_violated

    block = fully_cross_block([color, text, con_factor_within_trial],
                              [color, text],
                              [ExactlyKInARow(2, (color, red_color))])

    assert are_constraints_violated(
        block,
        {color: [red_color, red_color, blue_color, blue_color]}) == False
    assert are_constraints_violated(
        block, {color: [red_color, blue_color, red_color, blue_color]}) == True

    block = fully_cross_block([color, text, con_factor_within_trial],
                              [color, text],
                              [NoMoreThanKInARow(2, (color, red_color))])

    assert are_constraints_violated(
        block,
        {color: [red_color, blue_color, blue_color, blue_color]}) == False
    assert are_constraints_violated(
        block,
        {color: [red_color, red_color, blue_color, blue_color]}) == False
    assert are_constraints_violated(
        block, {color: [red_color, red_color, red_color, blue_color]}) == True
    assert are_constraints_violated(
        block, {color: [blue_color, red_color, red_color, red_color]}) == True
Ejemplo n.º 2
0
def test_kinarow_with_bad_factor():
    bogus_factor = Factor("f", ["a", "b", "c"])
    with pytest.raises(ValueError):
        fully_cross_block(design, crossing, [
            ExactlyKInARow(
                2, (bogus_factor, get_level_from_name(bogus_factor, "a")))
        ])
Ejemplo n.º 3
0
def test_exactlykinarow():
    backend_request = __run_kinarow(
        ExactlyKInARow(1, (color, get_level_from_name(color, "red"))))
    (expected_cnf, expected_fresh) = to_cnf_tseitin(
        And([
            If(1, Not(7)),
            If(And([Not(1), 7]), Not(13)),
            If(And([Not(7), 13]), Not(19))
        ]), 25)

    assert backend_request.fresh == expected_fresh
    assert backend_request.cnfs == [expected_cnf]

    backend_request = __run_kinarow(
        ExactlyKInARow(2, (color, get_level_from_name(color, "red"))))
    (expected_cnf, expected_fresh) = to_cnf_tseitin(
        And([
            If(1, And([7, Not(13)])),
            If(And([Not(1), 7]), And([13, Not(19)])),
            If(And([Not(7), 13]), 19),
            If(19, 13)
        ]), 25)

    assert backend_request.fresh == expected_fresh
    assert backend_request.cnfs == [expected_cnf]

    backend_request = __run_kinarow(
        ExactlyKInARow(3, (color, get_level_from_name(color, "red"))))
    (expected_cnf, expected_fresh) = to_cnf_tseitin(
        And([
            If(1, And([7, 13, Not(19)])),
            If(And([Not(1), 7]), And([13, 19])),
            If(19, 13),
            If(13, 7)
        ]), 25)

    assert backend_request.fresh == expected_fresh
    assert backend_request.cnfs == [expected_cnf]
Ejemplo n.º 4
0
def test_exactlykinarow_disallows_k_of_zero():
    with pytest.raises(ValueError):
        ExactlyKInARow(0, (color, get_level_from_name(color, "red")))