Skip to content

Commit

Permalink
Add unit test that candidates first executes the control last
Browse files Browse the repository at this point in the history
Regardless of whether randomize is enabled or not.
  • Loading branch information
9thbit committed Jun 26, 2019
1 parent 0780fdf commit 7fe81c3
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,29 @@ def control_func():

control_indexes = [run_experiment() for i in range(5)]
assert set(control_indexes) == set([0])


@pytest.mark.parametrize('randomize', [True, False])
def test_candidates_first_executes_control_last(randomize):
num_candidates = 100

def run_experiment():
exp = laboratory.Experiment()

counter = {'index': 0}
def increment_counter():
counter['index'] += 1

def control_func():
return counter['index']

cand_func = mock.Mock(side_effect=increment_counter)

exp.control(control_func)
for _ in range(num_candidates):
exp.candidate(cand_func)

return exp.conduct(randomize=randomize, candidates_first=True)

control_indexes = [run_experiment() for i in range(5)]
assert set(control_indexes) == {num_candidates}

0 comments on commit 7fe81c3

Please sign in to comment.