diff --git a/acceptance/test_stroop.py b/acceptance/test_stroop.py index a2321da4..737cb37d 100644 --- a/acceptance/test_stroop.py +++ b/acceptance/test_stroop.py @@ -7,6 +7,7 @@ from sweetpea import AtMostKInARow, ExactlyKInARow, Exclude from sweetpea import IterateGen from sweetpea import CrossBlock, synthesize_trials, synthesize_trials +from sweetpea import experiments_to_dicts, experiments_to_tuples # Basic setup color_list = ["red", "blue"] @@ -41,6 +42,31 @@ def test_correct_solution_count(design): assert len(experiments) == 24 +@pytest.mark.parametrize('design', permutations([color, text])) +def test_conversion_to_tuples_and_dicts(design): + crossing = [color, text] + constraints = [] + + block = CrossBlock(design, crossing, constraints) + experiments = synthesize_trials(block, 100, IterateGen) + + dicts = experiments_to_dicts(block, experiments) + tuples = experiments_to_tuples(block, experiments) + + assert len(dicts) == 24 + assert len(tuples) == 24 + + assert isinstance(dicts[0], list) + assert isinstance(tuples[0], list) + + assert len(dicts[0]) == 4 + assert len(tuples[0]) == 4 + + assert isinstance(dicts[0][0], dict) + assert isinstance(tuples[0][0], tuple) + + assert dicts[0][0]["color"] == "red" or dicts[0][0]["color"] == "blue" + assert tuples[0][0][0] == "red" or tuples[0][0][0] == "blue" @pytest.mark.parametrize('design', permutations([color, text, con_factor])) def test_correct_solution_count_with_congruence_factor_but_unconstrained(design): diff --git a/docs/_build/html/api/constraints.html b/docs/_build/html/api/constraints.html index e3c8f2d0..43b80e3f 100644 --- a/docs/_build/html/api/constraints.html +++ b/docs/_build/html/api/constraints.html @@ -206,7 +206,7 @@ class sweetpea.MinimumTrials(k)
Constrains an experiment to set the specified number of
minimum trials. See CrossBlock
and
-Repeat
for more information.
Repeat
for more information.
k (int) – minimum number of trials
diff --git a/docs/_build/html/api/main.html b/docs/_build/html/api/main.html index 51831b52..6eabdf28 100644 --- a/docs/_build/html/api/main.html +++ b/docs/_build/html/api/main.html @@ -365,7 +365,7 @@block (Block) – the experiment description that was provided to synthesize_trials()
experiments (List[Dict[str,list]]) – sequences generated by synthesize_trials()
experiments (List[Dict[str, list]]) – sequences generated by synthesize_trials()
block (Block) – the experiment description that was provided to synthesize_trials()
experiments (List[Dict[str, List[str]]]) – sequences generated by synthesize_trials()
experiments (List[Dict[str, list]]) – sequences generated by synthesize_trials()
factors (List[Factor]) – an alernative to block supplying factors to use as a crossing
trials (List[int]) – the indices of trials to tabulate, defaults to all trials
Saves each sequence of experiments to a file whoe name is +
Saves each sequence of experiments to a file whose name is file_prefix followed by an underscore, a number counting from 0, and “.csv”.
block (Block) – the experiment description that was provided to synthesize_trials()
experiments (List[Dict[str, List[str]]]) – sequences generated by synthesize_trials()
experiments (List[Dict[str, list]]) – sequences generated by synthesize_trials()
file_prefix (str) – file-name prefix
Converts a result from synthesize_trials()
, where each
+generated sequence is represented as a dictionary of lists, so that
+each generated sequence is instead represented as a list of dictionaries.
block (Block) – the experiment description that was provided to synthesize_trials()
experiments (List[Dict[str, list]]) – sequences generated by synthesize_trials()
a list of lists of dictionaries, where each dictionary maps each +factor name to the string name for the levels of the trial
+List[List[Dict[str, Any]]]
+Converts a result from synthesize_trials()
, where each
-generated sequence is represented as a dictory of lists, so that
+generated sequence is represented as a dictionary of lists, so that
each generated sequence is instead represented as a list of tuples.
block (Block) – the experiment description that was provided to synthesize_trials()
experiments (List[Dict[str, List[str]]]) – sequences generated by synthesize_trials()
experiments (List[Dict[str, list]]) – sequences generated by synthesize_trials()
List[List[Tuple[str, …]]]
+List[List[tuple]]