enumerable_weighted_sample 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1caa11ffaa50b63e7149ca09a7f9f2c245c74e81
4
- data.tar.gz: c35fd8bf89eacdd1174a19ec0a3cea0ac3083888
3
+ metadata.gz: 8263563d2736b3bd9e28aaac24a0ed1845d28975
4
+ data.tar.gz: f1c9c20a2c518b44cec323f0df2f06507dbdcae0
5
5
  SHA512:
6
- metadata.gz: 2953706bd28fb4913a847739a9a374e97e4a5a60b4c31874e808c7be9849c8429667e0c6b22df14815ce30e234c9c4ea0f27625b599e348f392688e74b41b3b7
7
- data.tar.gz: e1cd1bbde8c3dbb804bc7c4d2c52e7b7f705d77fb401e96230624803f932648032b7f07e329aa9162c586bae0bbf463dcd3a5bad0191eb0d3a7ecb8987b5a079
6
+ metadata.gz: 4d7cf27c2782b9c6d63266cdf45f57b91742bbd345c47314ce2c31f5d76ae70f09f7b9e9b126f497a1b0a374fd2ccdcf44f92e3d88fb3db043b5d3f35041a826
7
+ data.tar.gz: 4ec1e831bbe9cea41d9f588b50b2949b54438abb22a65895b98cfea9c7b47ca0684b6af87eedd05e74ee67fb243303f84be8bc25e5120633fe3bd54677b1b09a
@@ -49,69 +49,6 @@ module EnumerableWeightedSample
49
49
 
50
50
  end
51
51
 
52
-
53
- # Run this file directly for some quick and dirty inline testing
54
- if $0 == __FILE__
55
-
56
- class Array
57
- def summarize
58
- each_with_object(Hash.new(0)){|foo,h| h[foo] += 1 }.pretty
59
- end
60
- def pretty
61
- map(&:inspect).join(", ")
62
- end
63
- end
64
-
65
- class Hash
66
- def pretty
67
- sort_by{|_k,v|v}.map{|k,v| "#{k}: #{v}" }.join(", ")
68
- end
69
- end
70
-
71
- class Foo
72
- attr_accessor :name, :weight
73
- def initialize(name, weight)
74
- self.name = name
75
- self.weight = weight
76
- end
77
- def to_s
78
- name
79
- end
80
- def inspect
81
- "#{name}: #{weight}"
82
- end
83
- end
84
-
85
- SAMPLES = 1_000
86
-
87
- things = [
88
- Foo.new("foo", 1),
89
- Foo.new("bar", 2),
90
- Foo.new("baz", 199),
91
- Foo.new("bat", 198)
92
- ]
93
-
94
- # puts things.inverse_weighted_sample(100).summarize
95
-
96
- puts "input weights:"
97
- puts things.pretty
98
- puts
99
-
100
- puts "#{SAMPLES}x weighted samples:"
101
- weighted_things = things.weighted_sample(SAMPLES)
102
- puts weighted_things.map(&:name).summarize
103
- puts
104
-
105
- puts "#{SAMPLES}x inverse weighted samples:"
106
- inverse_weighted_things = things.inverse_weighted_sample(SAMPLES)
107
- puts inverse_weighted_things.map(&:name).summarize
108
- puts
109
-
110
- puts "#{SAMPLES}x iterative rebalance:"
111
- SAMPLES.times do
112
- things.weighted_sample.weight -= 1
113
- things.inverse_weighted_sample.weight += 1
114
- end
115
- puts things.pretty
116
-
52
+ class Array
53
+ include EnumerableWeightedSample
117
54
  end
@@ -1,3 +1,3 @@
1
1
  module EnumerableWeightedSample
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerable_weighted_sample
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christine Oen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-15 00:00:00.000000000 Z
11
+ date: 2017-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,6 +68,7 @@ files:
68
68
  - Rakefile
69
69
  - bin/console
70
70
  - bin/setup
71
+ - enumerable_weighted_sample-0.1.0.gem
71
72
  - enumerable_weighted_sample.gemspec
72
73
  - lib/enumerable_weighted_sample.rb
73
74
  - lib/enumerable_weighted_sample/version.rb