test/test_conductor.rb in conductor-0.4.1 vs test/test_conductor.rb in conductor-0.5.0

- old
+ new

@@ -15,10 +15,16 @@ should "select one of the specified options randomly" do selected = Conductor::Experiment.pick('a_group', ["a", "b", "c"]) # => value must be unique assert ["a", "b", "c"].include? selected end + should "use the cache if working" do + Conductor.cache.write('testing','value') + x = Conductor.cache.read('testing') + assert_equal x, 'value' + end + should "almost equally select each option if no weights exist" do a = 0 b = 0 c = 0 (1..1000).each do |x| @@ -107,33 +113,65 @@ context "conductor" do setup do seed_raw_data(100) Conductor::RollUp.process + Conductor.identity = ActiveSupport::SecureRandom.hex(16) end should "correctly RollUp daily data" do assert Conductor::Experiment::Daily.count > 2 assert Conductor::Experiment::Daily.all.detect {|x| x.conversions > 0} assert Conductor::Experiment::Daily.all.detect {|x| x.views > 0} assert Conductor::Experiment::Daily.all.detect {|x| x.conversion_value > 0} end + + should "correctly populate weighting table when selecting a value" do + selected = Conductor::Experiment.pick('a_group', ["a", "b", "c"]) + assert_equal 3, Conductor::Experiment::Weight.count + end - should "correctly populate weighting table" do - Conductor::Weights.compute + should "pull weights from the cache" do + Conductor::Experiment.pick('a_group', ["a", "b", "c"]) + + (1..100).each do |x| + Conductor.identity = ActiveSupport::SecureRandom.hex(16) + Conductor::Experiment.pick('a_group', ["a", "b", "c"]) + end + + # => if this works the history table should have only been updated one time not 101 so there should + # => be three records (one for a, b and c) + assert_equal 3, Conductor::Experiment::History.count end + + should "pull weights from the cache and then recreate weights when the alternative list changes" do + Conductor::Experiment.pick('a_group', ["a", "b", "c"]) + + (1..100).each do |x| + Conductor.identity = ActiveSupport::SecureRandom.hex(16) + Conductor::Experiment.pick('a_group', ["a", "b", "c"]) + end + + Conductor.identity = ActiveSupport::SecureRandom.hex(16) + Conductor::Experiment.pick('a_group', ["a", "c"]) + + # => if this works the history table should have only been updated one time not 101 so there should + # => be FIVE records (one for a, b and c and then one for a and c) + assert_equal 5, Conductor::Experiment::History.count + end end context "conductor" do should "populate the weighting table with equal weights if all new options are launched" do seed_raw_data(100, 7) # rollup Conductor::RollUp.process - # compute weights - Conductor::Weights.compute + # hit after rollup to populare weight table + Conductor.identity = ActiveSupport::SecureRandom.hex(16) + selected = Conductor::Experiment.pick('a_group', ["a", "b", "c"]) # this makes the following assumptions: # MINIMUM_LAUNCH_DAYS = 7 # each weight will be equal to 0.18 assert_equal 0.54, Conductor::Experiment::Weight.all.sum_it(:weight).to_f @@ -145,12 +183,13 @@ seed_raw_data(100, 14); # rollup Conductor::RollUp.process - # compute weights - Conductor::Weights.compute + # hit after rollup to populare weight table + Conductor.identity = ActiveSupport::SecureRandom.hex(16) + selected = Conductor::Experiment.pick('a_group', ["a", "b", "c"]) end should "populate the weighting table with different weights" do # if this DOES NOT work then each weight will be equal to 0.18 assert_not_equal 0.54, Conductor::Experiment::Weight.all.sum_it(:weight).to_f @@ -159,18 +198,10 @@ should "record the new weights in the weight history table in database" do assert Conductor::Experiment::History.count > 1 end should "return a weight 1.25 times higher than the highest weight for a newly launched and non-recorded alernative" do - seed_raw_data(100, 14) - - # rollup - Conductor::RollUp.process - - # compute weights - Conductor::Weights.compute - # get the highest weight max_weight = Conductor::Experiment::Weight.maximum(:weight) # pick something weights = Conductor::Experiment.weights('a_group', ["a", "b", "c", "f"]) # => value must be unique @@ -184,18 +215,17 @@ seed_raw_data(10, 6) # rollup Conductor::RollUp.process - # compute weights - Conductor::Weights.compute + # hit after rollup to populare weight table + Conductor.identity = ActiveSupport::SecureRandom.hex(16) + selected = Conductor::Experiment.pick('a_group', ["a", "b", "c"]) # make sure that launch_window values can be detected assert_not_nil Conductor::Experiment::History.find(:all, :conditions => 'launch_window > 0') end end - - private def wipe