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.

Parameters

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 @@

ExperimentsReturn type -

List[Dict[str, List[str]]]

+

List[Dict[str, list]]

@@ -379,7 +379,7 @@

ExperimentsParameters
@@ -404,7 +404,7 @@

ExperimentsParameters
@@ -415,31 +415,54 @@

Experiments
sweetpea.save_experiments_csv(block, experiments, file_prefix)
-

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”.

Parameters
+
+
+sweetpea.experiments_to_dicts(block, experiments)
+

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.

+
+
Parameters
+
+
+
Returns
+

a list of lists of dictionaries, where each dictionary maps each +factor name to the string name for the levels of the trial

+
+
Return type
+

List[List[Dict[str, Any]]]

+
+
+
+
-sweetpea.experiments_to_tuples(block, experiments, file_prefix)
+sweetpea.experiments_to_tuples(block, experiments)

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.

Parameters
Returns
@@ -447,7 +470,7 @@

ExperimentsReturn type -

List[List[Tuple[str, …]]]

+

List[List[tuple]]

diff --git a/docs/_build/html/genindex.html b/docs/_build/html/genindex.html index 33fac973..03549203 100644 --- a/docs/_build/html/genindex.html +++ b/docs/_build/html/genindex.html @@ -169,6 +169,8 @@

B

built-in function