diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index da1fa01..3dcef4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,3 +10,4 @@ require 'rubella' require 'rubella/storage' require 'rubella/input/base' require 'rubella/input/json' +require 'rubella/weighting/base' diff --git a/spec/unit/rubella/weighting/base/buckets_eql_spec.rb b/spec/unit/rubella/weighting/base/buckets_eql_spec.rb new file mode 100644 index 0000000..f1d3f56 --- /dev/null +++ b/spec/unit/rubella/weighting/base/buckets_eql_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Rubella::Weighting::Base, '.buckets=' do + + it "uses the given value" do + weighting = Rubella::Weighting::Base.new + + weighting.buckets = 5 + + expect(weighting.buckets).to eq(5) + end + + it "accepts one of 1, 2, 5, 10, 20, 50" do + weighting = Rubella::Weighting::Base.new + + [1, 2, 5, 10, 20, 50].each do |amount| + weighting.buckets = amount + expect(weighting.buckets).to eq(amount) + end + end + + it "throws an ArgumentError if the value is not 1, 2, 5, 10, 20, 50" do + weighting = Rubella::Weighting::Base.new + + expect{ weighting.buckets = 7 }.to raise_error(ArgumentError) + end + +end diff --git a/spec/unit/rubella/weighting/base/buckets_spec.rb b/spec/unit/rubella/weighting/base/buckets_spec.rb new file mode 100644 index 0000000..8df7ff9 --- /dev/null +++ b/spec/unit/rubella/weighting/base/buckets_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Rubella::Weighting::Base, '.buckets' do + + it "returns the current amount of buckets" do + weighting = Rubella::Weighting::Base.new 20 + + expect(weighting.buckets).to eq(20) + end + +end diff --git a/spec/unit/rubella/weighting/base/new_spec.rb b/spec/unit/rubella/weighting/base/new_spec.rb new file mode 100644 index 0000000..159b6bf --- /dev/null +++ b/spec/unit/rubella/weighting/base/new_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe Rubella::Weighting::Base, '.new' do + + it "creates a new Weighting instance" do + weighting = Rubella::Weighting::Base.new + + expect(weighting).to be_instance_of(Rubella::Weighting::Base) + end + + it "uses 10 buckets by default" do + weighting = Rubella::Weighting::Base.new + + expect(weighting.buckets).to eq(10) + end + + it "uses the given number of buckets" do + weighting = Rubella::Weighting::Base.new 5 + + expect(weighting.buckets).to eq(5) + end + +end diff --git a/spec/unit/rubella/weighting/base/parse_spec.rb b/spec/unit/rubella/weighting/base/parse_spec.rb new file mode 100644 index 0000000..03ae1e5 --- /dev/null +++ b/spec/unit/rubella/weighting/base/parse_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Rubella::Weighting::Base, '.parse' do + + it "raises NotImplementedError" do + weighting = Rubella::Weighting::Base.new + + expect{ weighting.parse(nil) }.to raise_error(NotImplementedError) + end + +end diff --git a/spec/unit/rubella/weighting/base/steps_spec.rb b/spec/unit/rubella/weighting/base/steps_spec.rb new file mode 100644 index 0000000..68e25ec --- /dev/null +++ b/spec/unit/rubella/weighting/base/steps_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Rubella::Weighting::Base, '@steps' do + + it "is always buckets/100" do + weighting = Rubella::Weighting::Implementation.new + + weighting.buckets = 20 + expect(weighting.steps).to eq(5) + + weighting.buckets = 10 + expect(weighting.steps).to eq(10) + end + +end + +class Rubella::Weighting::Implementation < Rubella::Weighting::Base + attr_reader :steps +end