<commit_before>require 'spec_helper'
require 'split/experiment'

describe Split::Experiment do
  before(:each) { Split.redis.flushall }

  it "should have a name" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.name.should eql('basket_text')
  end
  
  it "should have alternatives" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.alternatives.length.should be 2
  end
  
  it "should save to redis" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.save
    Split.redis.exists('basket_text').should be true
  end
  
  it "should return an existing experiment" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.save
    Split::Experiment.find('basket_text').name.should eql('basket_text')
  end

  describe 'winner' do
    it "should have no winner initially" do
      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
      experiment.winner.should be_nil
    end

    it "should allow you to specify a winner" do
      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
      experiment.winner = 'red'

      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
      experiment.winner.name.should == 'red'
    end
  end

  describe 'reset' do
    it 'should reset all alternatives' do
      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red', 'green')
      green = Split::Alternative.find('green', 'link_color')
      experiment.winner = 'green'

      experiment.next_alternative.name.should eql('green')
      green.increment_participation

      experiment.reset

      reset_green = Split::Alternative.find('green', 'link_color')<commit_msg>Experiment control test<commit_after>require 'spec_helper'
require 'split/experiment'

describe Split::Experiment do
  before(:each) { Split.redis.flushall }

  it "should have a name" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.name.should eql('basket_text')
  end
  
  it "should have alternatives" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.alternatives.length.should be 2
  end
  
  it "should save to redis" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.save
    Split.redis.exists('basket_text').should be true
  end
  
  it "should return an existing experiment" do
    experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
    experiment.save
    Split::Experiment.find('basket_text').name.should eql('basket_text')
  end

  describe 'control' do
    it 'should be the first alternative' do
      experiment = Split::Experiment.new('basket_text', 'Basket', "Cart")
      experiment.save
      experiment.control.name.should eql('Basket')
    end
  end

  describe 'winner' do
    it "should have no winner initially" do
      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
      experiment.winner.should be_nil
    end

    it "should allow you to specify a winner" do
      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
      experiment.winner = 'red'

      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red')
      experiment.winner.name.should == 'red'
    end
  end

  describe 'reset' do
    it 'should reset all alternatives' do
      experiment = Split::Experiment.find_or_create('link_color', 'blue', 'red', 'green')
      green = Split::Alternative.find('green', 'link_color')
      experiment.winner = 'green'

      experiment.next_alternative.name.should eql('green')
      green.increment_participation

      experiment.reset

      reset_green = Split::Alternative.find('green', 'link_color')
{'fraction_non_alphanumeric': 0.12558380902957966, 'fraction_numerical': 0.0005189413596263622, 'mean_word_length': 3.910828025477707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4518285', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1209, 'n_words': 282}