Sha256: 73d9e861bacb403fd86aca2014505071a59b0869415957bc884d291008d2dd31

Contents?: true

Size: 701 Bytes

Versions: 9

Compression:

Stored size: 701 Bytes

Contents

require 'spec_helper'
module Alf
  class Aggregator
    describe Variance do

      let(:rel){[
        {:qty => 10}, 
        {:qty => 20},
        {:qty => 30},
        {:qty => 40}
      ]}
      let(:expected) {
        vals = rel.map{|t| t[:qty]}
        mean = vals.inject(:+) / vals.size.to_f
        vals.collect{|v| (v - mean)**2 }.inject(:+) / vals.size.to_f
      }

      it 'should work when used standalone' do
        Variance.new{ qty }.aggregate(rel).should eq(expected)
      end

      it 'should install factory methods' do
        Aggregator.variance{ qty }.should be_a(Variance)
        Aggregator.variance{ qty }.aggregate(rel).should eq(expected)
      end

    end
  end
end 

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-aggregator/test_variance.rb
alf-core-0.14.0 spec/unit/alf-aggregator/test_variance.rb
alf-core-0.13.1 spec/unit/alf-aggregator/test_variance.rb
alf-core-0.13.0 spec/unit/alf-aggregator/test_variance.rb
alf-0.12.2 spec/unit/alf-core/aggregator/test_variance.rb
alf-0.12.1 spec/unit/alf-core/aggregator/test_variance.rb
alf-0.12.0 spec/unit/alf-core/aggregator/test_variance.rb
alf-0.11.1 spec/unit/alf-core/aggregator/test_variance.rb
alf-0.11.0 spec/unit/alf-core/aggregator/test_variance.rb