Sha256: 38d3c7f8a763ce4882da03f4996247c04935cf91cc3202ed357e837ff6e99593

Contents?: true

Size: 941 Bytes

Versions: 22

Compression:

Stored size: 941 Bytes

Contents

require 'test_helper'

class RandomPercentageSegmenterTest < Minitest::Test

  def setup
    @segmenter = Verdict::Segmenters::RandomPercentageSegmenter.new(Verdict::Experiment.new('test'))
    @segmenter.group :segment1, 50
    @segmenter.group :segment2, 50
    @segmenter.verify!
  end

  def test_random_assignment
    @segmenter.random = Random.new(1)

    groups = { segment1: 0, segment2: 0 }
    100.times do |n|
      group = @segmenter.assign(n.to_s, nil, nil)
      groups[group.handle.to_sym] += 1
    end

    assert_equal 54, groups[:segment1]
    assert_equal 46, groups[:segment2]
  end

  def test_random_assignment_with_different_seed
    @segmenter.random = Random.new(2)

    groups = { segment1: 0, segment2: 0 }
    100.times do |n|
      group = @segmenter.assign(n.to_s, nil, nil)
      groups[group.handle.to_sym] += 1
    end

    assert_equal 44, groups[:segment1]
    assert_equal 56, groups[:segment2]
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
verdict-0.16.1 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.16.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.15.2 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.15.1 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.15.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.14.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.13.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.12.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.11.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.10.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.9.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.8.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.7.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.6.3 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.6.2 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.6.1 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.6.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.5.0 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.4.1 test/segmenters/random_percentage_segmenter_test.rb
verdict-0.4.0 test/segmenters/random_percentage_segmenter_test.rb