Sha256: a7867081f8c19a508791c3bc6aaaece11de3271cdc47263886f805f968d3e100

Contents?: true

Size: 828 Bytes

Versions: 2

Compression:

Stored size: 828 Bytes

Contents

# encoding: utf-8

require 'spec_helper'

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

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

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

    it { should be_nil }
  end

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

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

  context 'when the sum of squares is infinte' 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/variance/class_methods/finalize_spec.rb
axiom-0.1.1 spec/unit/axiom/aggregate/variance/class_methods/finalize_spec.rb