splashy 0.0.1 → 0.0.2
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.
- data/README.markdown +7 -0
- data/VERSION +1 -1
- data/lib/splashy/buckets.rb +13 -2
- data/splashy.gemspec +58 -0
- data/test/test_splashy_buckets.rb +16 -0
- metadata +5 -4
data/README.markdown
CHANGED
@@ -43,6 +43,13 @@ buckets.select
|
|
43
43
|
# }
|
44
44
|
```
|
45
45
|
|
46
|
+
Changelog
|
47
|
+
=========
|
48
|
+
|
49
|
+
* 0.0.2 - Raise `ArgumentError` when trying to add to a bucket that doesn't
|
50
|
+
exist, don't consider an empty bucket "satisfied".
|
51
|
+
* 0.0.1 - Initial release.
|
52
|
+
|
46
53
|
Contributing
|
47
54
|
============
|
48
55
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/splashy/buckets.rb
CHANGED
@@ -10,8 +10,9 @@ module Splashy
|
|
10
10
|
end
|
11
11
|
@wanted_distribution = wanted_distribution
|
12
12
|
@wanted_count = wanted_count
|
13
|
-
@buckets =
|
14
|
-
|
13
|
+
@buckets = {}
|
14
|
+
@wanted_distribution.keys.each do |bucket_name|
|
15
|
+
@buckets[bucket_name] = Bucket.new( bucket_name )
|
15
16
|
end
|
16
17
|
@total_count = 0
|
17
18
|
end
|
@@ -42,6 +43,9 @@ module Splashy
|
|
42
43
|
|
43
44
|
# Public: Add a single element to a bucket.
|
44
45
|
def add( bucket_name, element )
|
46
|
+
unless @wanted_distribution[bucket_name]
|
47
|
+
raise ArgumentError.new( "#{bucket_name.inspect} is not a valid bucket." )
|
48
|
+
end
|
45
49
|
@buckets[bucket_name] << element
|
46
50
|
@total_count += 1
|
47
51
|
end
|
@@ -130,6 +134,13 @@ module Splashy
|
|
130
134
|
)
|
131
135
|
end
|
132
136
|
|
137
|
+
empty_buckets = @buckets.keys.select{ |name| @buckets[name].empty? }
|
138
|
+
unless empty_buckets.empty?
|
139
|
+
raise DistributionUnsatisfiedError.new(
|
140
|
+
"The following buckets are empty: #{empty_buckets.map{|b| b}.join(', ')}."
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
133
144
|
if @wanted_count
|
134
145
|
if @total_count < @wanted_count
|
135
146
|
raise DistributionUnsatisfiedError.new(
|
data/splashy.gemspec
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{splashy}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tyson Tate"]
|
12
|
+
s.date = %q{2011-12-09}
|
13
|
+
s.description = %q{Simple distribution-based sampling of arbitrary objects from any number of buckets. Splashy. Buckets. Get it!?}
|
14
|
+
s.email = %q{tyson@tysontate.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"buckets.gemspec",
|
27
|
+
"lib/splashy.rb",
|
28
|
+
"lib/splashy/bucket.rb",
|
29
|
+
"lib/splashy/buckets.rb",
|
30
|
+
"splashy.gemspec",
|
31
|
+
"test/helper.rb",
|
32
|
+
"test/test_splashy_buckets.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/tysontate/splashy}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.4.2}
|
38
|
+
s.summary = %q{Simple distribution-based sampling of arbitrary objects from buckets.}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
46
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
49
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
50
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
@@ -61,6 +61,22 @@ describe Splashy::Buckets do
|
|
61
61
|
@buckets.select
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
it "fails when trying to add to an invalid bucket" do
|
66
|
+
@buckets = Splashy::Buckets.new({ :a => 0.80, :b => 0.2 } )
|
67
|
+
assert_raises( ArgumentError ) do
|
68
|
+
@buckets.add( :x, "oops" )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "fails with distribution being such that desired count can't be met" do
|
73
|
+
@buckets = Splashy::Buckets.new({ :a => 0.80, :b => 0.1, :c => 0.10 } )
|
74
|
+
fill_with_counts( 1, 2, 0 )
|
75
|
+
assert !@buckets.satisfied?
|
76
|
+
assert_raises( Splashy::DistributionUnsatisfiedError ) do
|
77
|
+
@buckets.select
|
78
|
+
end
|
79
|
+
end
|
64
80
|
end
|
65
81
|
|
66
82
|
describe "success" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splashy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tyson Tate
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-09 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/splashy.rb
|
85
85
|
- lib/splashy/bucket.rb
|
86
86
|
- lib/splashy/buckets.rb
|
87
|
+
- splashy.gemspec
|
87
88
|
- test/helper.rb
|
88
89
|
- test/test_splashy_buckets.rb
|
89
90
|
has_rdoc: true
|