Skip to content

Commit 7fe81c3

Browse files
committed
Add unit test that candidates first executes the control last
Regardless of whether randomize is enabled or not.
1 parent 0780fdf commit 7fe81c3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/test_experiment.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,29 @@ def control_func():
173173

174174
control_indexes = [run_experiment() for i in range(5)]
175175
assert set(control_indexes) == set([0])
176+
177+
178+
@pytest.mark.parametrize('randomize', [True, False])
179+
def test_candidates_first_executes_control_last(randomize):
180+
num_candidates = 100
181+
182+
def run_experiment():
183+
exp = laboratory.Experiment()
184+
185+
counter = {'index': 0}
186+
def increment_counter():
187+
counter['index'] += 1
188+
189+
def control_func():
190+
return counter['index']
191+
192+
cand_func = mock.Mock(side_effect=increment_counter)
193+
194+
exp.control(control_func)
195+
for _ in range(num_candidates):
196+
exp.candidate(cand_func)
197+
198+
return exp.conduct(randomize=randomize, candidates_first=True)
199+
200+
control_indexes = [run_experiment() for i in range(5)]
201+
assert set(control_indexes) == {num_candidates}

0 commit comments

Comments
 (0)