Permalink
Browse files

Change control value to support any order

  • Loading branch information...
1 parent 0157190 commit ff7eb4a1949d430c4e7409c2b67ed1809a4d7b8c Ariel Salomon committed with sideshowbandana Sep 19, 2011
Showing with 9 additions and 11 deletions.
  1. +9 −11 lib/vanity/experiment/ab_test.rb
@@ -149,9 +149,8 @@ def metrics(*args)
# puts "#{alts.count} alternatives, with the colors: #{alts.map(&:value).join(", ")}"
def alternatives(*args)
@alternatives = args.empty? ? [true, false] : args.clone
- if @control
- @alternatives.delete(@control)
- @alternatives.push(@control) # move to end
+ if @control && !@alternatives.include?(@control)
+ @alternatives.push(@control) # add to end
end
class << self
define_method :alternatives, instance_method(:_alternatives)
@@ -335,9 +334,8 @@ def control_percent(pct)
def control_value(value)
@control = value
- if @alternatives
- @alternatives.delete(@control)
- @alternatives.push(@control) # move to end
+ if @alternatives && !@alternatives.include?(@control)
+ @alternatives.push(@control) # add to end
end
end
@@ -545,16 +543,16 @@ def alternative_for(identity)
end
def hash_to_alternative(id_hash)
- alternatives_count = @alternatives.size
- if @test_pct
+ alternatives = *(0..(@alternatives.size - 1))
+ if @test_pct && @control
if (id_hash % 100 >= @test_pct)
- return alternatives_count-1 #@control
+ return @alternatives.index(@control)
else
id_hash = id_hash / 100
- alternatives_count -= 1
+ alternatives.delete(@alternatives.index(@control))
end
end
- return id_hash % alternatives_count
+ return alternatives[id_hash % alternatives.count]
end

0 comments on commit ff7eb4a

Please sign in to comment.