From ad54bc6a7b3ddd69e49caadb3e95c0705af2281b Mon Sep 17 00:00:00 2001 From: Stormwind Date: Wed, 21 Oct 2015 09:38:59 +0200 Subject: [PATCH] Add tests for Rubella::Weighting::PerValue --- spec/spec_helper.rb | 1 + .../rubella/weighting/per_value/parse_spec.rb | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 spec/unit/rubella/weighting/per_value/parse_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b580b19..d440ded 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,3 +12,4 @@ require 'rubella/input/base' require 'rubella/input/json' require 'rubella/weighting/base' require 'rubella/weighting/per_count' +require 'rubella/weighting/per_value' diff --git a/spec/unit/rubella/weighting/per_value/parse_spec.rb b/spec/unit/rubella/weighting/per_value/parse_spec.rb new file mode 100644 index 0000000..58e5841 --- /dev/null +++ b/spec/unit/rubella/weighting/per_value/parse_spec.rb @@ -0,0 +1,47 @@ +require 'spec_helper' + +describe Rubella::Weighting::PerValue, '.parse' do + + it "returns a Rubella::Storage object" do + input = [] + # input = Rubella::Input::Base.new [] # Does not work atm FIX IT! + weighting = Rubella::Weighting::PerValue.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, 15]] + weighting = Rubella::Weighting::PerValue.new 5 + + storage = weighting.parse(input) + + expect(storage.length).to eq(1) + expect(storage.dataset_length).to eq(5) + end + + it "gives maximum intensity, if all cores have the same load" do + input = [[10, 20, 10, 30], [10, 40, 10, 20], [40, 40, 40, 40]] + weighting = Rubella::Weighting::PerValue.new 10 + + storage = weighting.parse(input) + + expect(storage.data[2][4]).to eq(1.0) + end + + it "computes the intensity on the number of cores" do + input = [[10, 20, 10, 30], [20, 40, 20, 20], [40, 40, 40, 40]] + weighting = Rubella::Weighting::PerValue.new 10 + + storage = weighting.parse(input) + + expect(storage.data).to eq( + [ + [0.0, 0.5, 0.25, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.75, 0.0, 0.25, 0.0, 0.0, 0.0, 0.0, 0.0], + [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0] + ] + ) + end + +end