verdict 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8efebedf53fee289950045fc2396359440dc0e15
4
- data.tar.gz: 94bba89fe604abab1cd2f60b45b66bff0424ee75
3
+ metadata.gz: ad853660b0d33894ee603240d466111f9d451112
4
+ data.tar.gz: e304f2bf2f68695e90be81aa9b10dceb24bb3603
5
5
  SHA512:
6
- metadata.gz: 538a77d48203d92c91a42072d9f64e60f9ab3b1d8ee857d380bfcd61328c73f1d9d96682db1a5dbb1c43c8ae4d52c57b38d156863408b77673b879c17ac4fa1a
7
- data.tar.gz: c9535d06da2da5bef7a547b9565515f227dc8789d5d690d0b68867a5b5b6835a6dcf7645ee2dfa7a37d072d47cb22b932a0d014bc51c83dc4cff3734de03a0f0
6
+ metadata.gz: e60e581e4a84de8ed7acede5131765c2ab95ffb4a90cf97c65e5d65b28157b289057b451317a4ff155b4ab48b4d64104f2b7973cc8486b4880711fc4287026b0
7
+ data.tar.gz: 89c30e1b36f5b247607210a25fa29939e500346012167ab0c04295bb313dbea144bd2109e70d4b269dde0680ac9a10be0e741de6c8faedbedc52f704b2d328c7
@@ -26,7 +26,7 @@ module Verdict
26
26
  end
27
27
 
28
28
  def assign(identifier, subject, context)
29
- percentile = Digest::MD5.hexdigest("#{@experiment.handle}#{identifier}").to_i(16) % 100
29
+ percentile = Digest::MD5.hexdigest("#{@experiment.handle}#{identifier}#{self.class.salt}").to_i(16) % 100
30
30
  groups.values.find { |group| group.percentile_range.include?(percentile) }
31
31
  end
32
32
 
@@ -51,6 +51,10 @@ module Verdict
51
51
  super(options).merge(percentage: percentage_size)
52
52
  end
53
53
  end
54
+
55
+ class << self
56
+ attr_accessor :salt
57
+ end
54
58
  end
55
59
  end
56
60
  end
@@ -0,0 +1,18 @@
1
+ module Verdict
2
+ module Segmenters
3
+ class RandomPercentageSegmenter < FixedPercentageSegmenter
4
+
5
+ attr_accessor :random
6
+
7
+ def initialize(*args)
8
+ super
9
+ @random = Random.new
10
+ end
11
+
12
+ def assign(identifier, subject, context)
13
+ percentile = @random.rand(100)
14
+ groups.values.find { |group| group.percentile_range.include?(percentile) }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,4 +1,5 @@
1
1
  require 'verdict/segmenters/base_segmenter'
2
2
  require 'verdict/segmenters/static_segmenter'
3
3
  require 'verdict/segmenters/fixed_percentage_segmenter'
4
+ require 'verdict/segmenters/random_percentage_segmenter'
4
5
  require 'verdict/segmenters/rollout_segmenter'
@@ -1,3 +1,3 @@
1
1
  module Verdict
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -85,4 +85,25 @@ class FixedPercentageSegmenterTest < Minitest::Test
85
85
  assert_equal 'rest', json['handle']
86
86
  assert_equal 67, json['percentage']
87
87
  end
88
+
89
+ def test_salt_changes_segmentation
90
+ s = Verdict::Segmenters::FixedPercentageSegmenter.new(Verdict::Experiment.new('test'))
91
+ s.group :a, 50
92
+ s.group :b, 50
93
+ s.verify!
94
+
95
+ groups = { 'a' => 0, 'b' => 0 }
96
+ 100.times { |n| groups[s.assign(n.to_s, nil, nil).handle] += 1 }
97
+
98
+ assert_equal 54, groups['a']
99
+ assert_equal 46, groups['b']
100
+
101
+ Verdict::Segmenters::FixedPercentageSegmenter.stubs(:salt).returns("whatever")
102
+
103
+ groups = { 'a' => 0, 'b' => 0 }
104
+ 100.times { |n| groups[s.assign(n.to_s, nil, nil).handle] += 1 }
105
+
106
+ assert_equal 50, groups['a']
107
+ assert_equal 50, groups['b']
108
+ end
88
109
  end
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ class RandomPercentageSegmenterTest < Minitest::Test
4
+
5
+ def setup
6
+ @segmenter = Verdict::Segmenters::RandomPercentageSegmenter.new(Verdict::Experiment.new('test'))
7
+ @segmenter.group :segment1, 50
8
+ @segmenter.group :segment2, 50
9
+ @segmenter.verify!
10
+ end
11
+
12
+ def test_random_assignment
13
+ @segmenter.random = Random.new(1)
14
+
15
+ groups = { segment1: 0, segment2: 0 }
16
+ 100.times do |n|
17
+ group = @segmenter.assign(n.to_s, nil, nil)
18
+ groups[group.handle.to_sym] += 1
19
+ end
20
+
21
+ assert_equal 54, groups[:segment1]
22
+ assert_equal 46, groups[:segment2]
23
+ end
24
+
25
+ def test_random_assignment_with_different_seed
26
+ @segmenter.random = Random.new(2)
27
+
28
+ groups = { segment1: 0, segment2: 0 }
29
+ 100.times do |n|
30
+ group = @segmenter.assign(n.to_s, nil, nil)
31
+ groups[group.handle.to_sym] += 1
32
+ end
33
+
34
+ assert_equal 44, groups[:segment1]
35
+ assert_equal 56, groups[:segment2]
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verdict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -105,6 +105,7 @@ files:
105
105
  - lib/verdict/segmenters.rb
106
106
  - lib/verdict/segmenters/base_segmenter.rb
107
107
  - lib/verdict/segmenters/fixed_percentage_segmenter.rb
108
+ - lib/verdict/segmenters/random_percentage_segmenter.rb
108
109
  - lib/verdict/segmenters/rollout_segmenter.rb
109
110
  - lib/verdict/segmenters/static_segmenter.rb
110
111
  - lib/verdict/storage.rb
@@ -122,6 +123,7 @@ files:
122
123
  - test/metadata_test.rb
123
124
  - test/rake_tasks_test.rb
124
125
  - test/segmenters/fixed_percentage_segmenter_test.rb
126
+ - test/segmenters/random_percentage_segmenter_test.rb
125
127
  - test/segmenters/rollout_segmenter_test.rb
126
128
  - test/segmenters/static_segmenter_test.rb
127
129
  - test/storage/memory_subject_storage_test.rb
@@ -147,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
149
  version: '0'
148
150
  requirements: []
149
151
  rubyforge_project:
150
- rubygems_version: 2.0.14
152
+ rubygems_version: 2.0.3
151
153
  signing_key:
152
154
  specification_version: 4
153
155
  summary: A library to centrally define experiments for your application, and collect
@@ -162,9 +164,9 @@ test_files:
162
164
  - test/metadata_test.rb
163
165
  - test/rake_tasks_test.rb
164
166
  - test/segmenters/fixed_percentage_segmenter_test.rb
167
+ - test/segmenters/random_percentage_segmenter_test.rb
165
168
  - test/segmenters/rollout_segmenter_test.rb
166
169
  - test/segmenters/static_segmenter_test.rb
167
170
  - test/storage/memory_subject_storage_test.rb
168
171
  - test/storage/redis_subject_storage_test.rb
169
172
  - test/test_helper.rb
170
- has_rdoc: