0
0
Fork 0

Add tests for Rubella::Weighting::Base

This commit is contained in:
Stormwind 2015-10-20 11:29:56 +02:00
parent b87dfc273e
commit b53d134e2e
6 changed files with 93 additions and 0 deletions

View File

@ -10,3 +10,4 @@ require 'rubella'
require 'rubella/storage'
require 'rubella/input/base'
require 'rubella/input/json'
require 'rubella/weighting/base'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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