def test_no_solutions_without_override_flag(): block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 500) assert block.crossing_size() == 6 assert len(experiments) == 0 assert_no_repetition(experiments)
def test_correct_solution_count_with_congruence_factor_and_constrained(design): crossing = [color, text] constraints = [NoMoreThanKInARow(1, ("congruent?", "con"))] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 12
def test_correct_solution_count_with_congruence_factor_and_constrained_exactly(design): crossing = [[color, text], [text, mix]] constraints = [exactly_k_in_a_row(2, con_factor)] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 32
def test_correct_solution_count_with_repeated_color_factor_but_unconstrained(design): crossing = [[color, text], [text, mix]] constraints = [] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 96
def test_correct_solution_count(design): crossing = [[color, mix], [text, mix]] constraints = [] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 96
def test_correct_solution_count_with_congruence_factor_and_constrained(design): crossing = [[color, text], [text, mix]] constraints = [at_most_k_in_a_row(1, (con_factor, get_level_from_name(con_factor, "con")))] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 48
def test_correct_solution_count_when_unconstrained(design): crossing = [color, text] constraints = [] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 24
def test_correct_solution_count_with_repeated_color_factor_and_no_repetition_allowed(design): crossing = [[color, text], [mix, text]] constraints = [exclude(repeated_color_factor, get_level_from_name(repeated_color_factor, "yes"))] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 32
def test_correct_solution_count_when_crossing_with_derived_transition(design): crossing = [color, repeated_color_factor] constraints = [] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 4
def test_correct_solution_count_with_repeated_color_factor_and_no_repetition_allowed(design): crossing = [color, text] constraints = [NoMoreThanKInARow(0, ("repeated color?", "yes"))] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 8
def test_correct_solution_count_when_constrained(design): crossing = [direction, congruent_factor] constraints = [at_most_k_in_a_row(1, congruent_factor)] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 500) assert len(experiments) == 128
def test_correct_solution_count_with_congruence_factor_but_unconstrained( design): crossing = [congruency] constraints = [] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 6
def test_correct_solution_count_with_override_flag(): block = fully_cross_block(design, crossing, constraints, require_complete_crossing=False) experiments = synthesize_trials_non_uniform(block, 500) assert block.crossing_size() == 5 assert len(experiments) == 120 assert_no_repetition(experiments)
def test_correct_solution_count_when_bookends_must_not_be_congruent(design): crossing = [color, text] # Require both bookends to not be congruent. constraints = [NoMoreThanKInARow(0, ("congruent bookend?", "yes"))] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 4
def test_correct_solution_count_with_repeated_color_factor_and_constrained(design): crossing = [[color, text], [mix, text]] constraints = [at_most_k_in_a_row(1, (repeated_color_factor, get_level_from_name(repeated_color_factor, "yes")))] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) # With only two colors, there can never be two color repetitons anyways, # so the total should still be the same. assert len(experiments) == 96
def test_correct_solution_count_with_repeated_color_factor_and_constrained(design): crossing = [color, text] constraints = [NoMoreThanKInARow(1, ("repeated color?", "yes"))] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) # With only two colors, there can never be two color repetitons anyways, # so the total should still be the same. assert len(experiments) == 24
def test_correct_solution_count_when_bookends_must_not_match_each_other( design): crossing = [color, text] # Require both bookends to be incongruent with each other. constraints = [at_most_k_in_a_row(1, congruent_bookend)] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 16
def test_correct_solution_count_with_repeated_color_and_text_factors_and_constrained(design): crossing = [[color, text], [mix, text]] constraints = [ at_most_k_in_a_row(1, (repeated_color_factor, get_level_from_name(repeated_color_factor, "yes"))), at_most_k_in_a_row(1, (repeated_text_factor, get_level_from_name(repeated_text_factor, "yes"))) ] block = multiple_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 96
def test_correct_solution_count_when_transition_in_crossing_and_constrained( design): crossing = [direction, repeated_color_factor] constraints = [ at_most_k_in_a_row(1, (color, get_level_from_name(color, "red"))) ] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 32
def test_correct_solution_count_when_bookends_must_not_be_congruent(design): crossing = [color, text] # Require both bookends to not be congruent. constraints = [ exclude(congruent_bookend, get_level_from_name(congruent_bookend, "yes")) ] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 4
def test_that_design_is_correctly_constrained(design): crossing = [color, motion, task] k = 2 constraints = [ NoMoreThanKInARow(k, task_transition), NoMoreThanKInARow(k, response_transition) ] block = fully_cross_block(design, crossing, constraints) experiments = synthesize_trials_non_uniform(block, 100) assert len(experiments) == 100, "Design: %s" % str(list(map(lambda f: f.name, design))) for c in constraints: assert_nomorethankinarow(c, experiments)
def test_correct_solution_count_with_override_flag_and_multiple_trials_excluded( ): # With this constraint, there should only be ONE allowed crossing, and therefore one solution. constraints = [ exclude(stimulus_configuration, get_level_from_name(stimulus_configuration, "legal")) ] block = fully_cross_block(design, crossing, constraints, require_complete_crossing=False) experiments = synthesize_trials_non_uniform(block, 500) assert block.crossing_size() == 1 assert len(experiments) == 1 assert_no_repetition(experiments)
def response_repeat(response): return response[0] == response[1] def response_switch(response): return not response_repeat(response) resp_transition = factor("response_transition", [ derived_level("repeat", transition(response_repeat, [response])), derived_level("switch", transition(response_switch, [response])) ]) # DEFINE SEQUENCE CONSTRAINTS k = 7 constraints = [no_more_than_k_in_a_row(k, resp_transition)] # DEFINE EXPERIMENT design = [color, word, congruency, resp_transition, response] crossing = [color, word, resp_transition] block = fully_cross_block(design, crossing, constraints) # SOLVE experiments = synthesize_trials_non_uniform(block, 5) print_experiments(block, experiments)