Sha256: 351db9386ea00f92c83882b077ccf5fc25632f30d80417ecbb0480a1955119e0

Contents?: true

Size: 848 Bytes

Versions: 2

Compression:

Stored size: 848 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

describe Aggregate::StandardDeviation, '.finalize' do
  subject { object.finalize(accumulator) }

  let(:object)      { described_class               }
  let(:accumulator) { [count, mean, sum_of_squares] }

  context 'when the variance is 0.0' do
    let(:count)          { 0   }
    let(:mean)           { nil }
    let(:sum_of_squares) { 0.0 }

    it { should be_nil }
  end

  context 'when the variance is not 0.0' do
    let(:count)          { 6    }
    let(:mean)           { 3.5  }
    let(:sum_of_squares) { 17.5 }

    it { should be_within(0.01).of(1.70) }
  end

  context 'when the variance is infinite' do
    let(:count)          { 1               }
    let(:mean)           { nil             }
    let(:sum_of_squares) { Float::INFINITY }

    it { should eql(Float::INFINITY) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.2.0 spec/unit/axiom/aggregate/standard_deviation/class_methods/finalize_spec.rb
axiom-0.1.1 spec/unit/axiom/aggregate/standard_deviation/class_methods/finalize_spec.rb