Add tests for Rubella::Weighting::PerCount
This commit is contained in:
parent
b53d134e2e
commit
47aa9c301a
|
@ -11,3 +11,4 @@ require 'rubella/storage'
|
|||
require 'rubella/input/base'
|
||||
require 'rubella/input/json'
|
||||
require 'rubella/weighting/base'
|
||||
require 'rubella/weighting/per_count'
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Rubella::Weighting::PerCount, '.buckets=' do
|
||||
|
||||
it "uses the given value" do
|
||||
weighting = Rubella::Weighting::PerCount.new
|
||||
|
||||
weighting.buckets = 5
|
||||
|
||||
expect(weighting.buckets).to eq(5)
|
||||
end
|
||||
|
||||
it "accepts every given value" do
|
||||
weighting = Rubella::Weighting::PerCount.new
|
||||
|
||||
amount = rand(100)
|
||||
weighting.buckets = amount
|
||||
|
||||
expect(weighting.buckets).to eq(amount)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,22 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Rubella::Weighting::PerCount, '.new' do
|
||||
|
||||
it "creates a new Weighting instance" do
|
||||
weighting = Rubella::Weighting::PerCount.new
|
||||
|
||||
expect(weighting).to be_instance_of(Rubella::Weighting::PerCount)
|
||||
end
|
||||
|
||||
it "uses 7 buckets by default" do
|
||||
weighting = Rubella::Weighting::PerCount.new
|
||||
|
||||
expect(weighting.buckets).to eq(7)
|
||||
end
|
||||
|
||||
it "uses the given number of buckets" do
|
||||
weighting = Rubella::Weighting::PerCount.new 5
|
||||
|
||||
expect(weighting.buckets).to eq(5)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Rubella::Weighting::PerCount, '.parse' do
|
||||
|
||||
it "returns a Rubella::Storage object" do
|
||||
input = []
|
||||
# input = Rubella::Input::Base.new [] # Does not work atm FIX IT!
|
||||
weighting = Rubella::Weighting::PerCount.new
|
||||
|
||||
expect(weighting.parse(input)).to be_instance_of(Rubella::Storage)
|
||||
end
|
||||
|
||||
it "splits data in given amount of buckets" do
|
||||
input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
|
||||
weighting = Rubella::Weighting::PerCount.new 7
|
||||
|
||||
storage = weighting.parse(input)
|
||||
|
||||
expect(storage.length).to eq(2)
|
||||
expect(storage.dataset_length).to eq(7)
|
||||
end
|
||||
|
||||
it "gives maximum intensity (1) to the maximum value" do
|
||||
input = [1, 2, 1, 3, 1, 4, 10, 2, 1, 2, 3, 4, 2, 1]
|
||||
weighting = Rubella::Weighting::PerCount.new 7
|
||||
|
||||
storage = weighting.parse(input)
|
||||
|
||||
expect(storage.data[0][6]).to eq(1.0)
|
||||
end
|
||||
|
||||
it "computes the intensity on the maximum value" do
|
||||
input = [1, 2, 1, 3, 1, 4, 5, 2, 1, 2, 3, 4, 2, 1]
|
||||
weighting = Rubella::Weighting::PerCount.new 7
|
||||
|
||||
storage = weighting.parse(input)
|
||||
|
||||
expect(storage.data).to eq(
|
||||
[[0.2, 0.4, 0.2, 0.6, 0.2, 0.8, 1.0], [0.4, 0.2, 0.4, 0.6, 0.8, 0.4, 0.2]]
|
||||
)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue