Skip to content

Commit d69048a

Browse files
semanticartandrew
authored andcommitted
Fix combined experiments (#502)
1. always pass all alternatives to prevent unintentional version bumps 2. return the chosen alternative from `ab_combined_test` Fixes #500
1 parent 13e11b6 commit d69048a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lib/split/combined_experiments_helper.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def ab_combined_test(metric_descriptor, control = nil, *alternatives)
66
raise(Split::InvalidExperimentsFormatError, 'Unable to find experiment #{metric_descriptor} in configuration') if experiment[:combined_experiments].nil?
77

88
alternative = nil
9+
weighted_alternatives = nil
910
experiment[:combined_experiments].each do |combined_experiment|
1011
if alternative.nil?
1112
if control
@@ -15,9 +16,15 @@ def ab_combined_test(metric_descriptor, control = nil, *alternatives)
1516
alternative = ab_test(combined_experiment, normalized_alternatives[0], *normalized_alternatives[1])
1617
end
1718
else
18-
ab_test(combined_experiment, [{alternative => 1}])
19+
weighted_alternatives ||= experiment[:alternatives].each_with_object({}) do |alt, memo|
20+
alt = Alternative.new(alt, experiment[:name]).name
21+
memo[alt] = (alt == alternative ? 1 : 0)
22+
end
23+
24+
ab_test(combined_experiment, [weighted_alternatives])
1925
end
2026
end
27+
alternative
2128
end
2229

2330
def find_combined_experiment(metric_descriptor)

spec/combined_experiments_helper_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
end
4747
end
4848

49-
it "uses same alternatives for all sub experiments " do
49+
it "uses same alternative for all sub experiments and returns the alternative" do
5050
allow(self).to receive(:get_alternative) { "test-alt" }
5151
expect(self).to receive(:ab_test).with(:exp_1_click, {"control"=>0.5}, {"test-alt"=>0.5}) { "test-alt" }
52-
expect(self).to receive(:ab_test).with(:exp_1_scroll, [{"test-alt" => 1}] )
52+
expect(self).to receive(:ab_test).with(:exp_1_scroll, [{"control" => 0, "test-alt" => 1}])
5353

54-
ab_combined_test('combined_exp_1')
54+
expect(ab_combined_test('combined_exp_1')).to eq('test-alt')
5555
end
5656
end
5757
end

0 commit comments

Comments
 (0)