Sha256: 68227018fdf540c972617330da13385cf69b23c6e24b2a1079f7405dec8027fc

Contents?: true

Size: 843 Bytes

Versions: 4

Compression:

Stored size: 843 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_close(1.70, 0.01) }
  end

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-0.0.7 spec/unit/veritas/aggregate/standard_deviation/class_methods/finalize_spec.rb
veritas-0.0.6 spec/unit/veritas/aggregate/standard_deviation/class_methods/finalize_spec.rb
veritas-0.0.5 spec/unit/veritas/aggregate/standard_deviation/class_methods/finalize_spec.rb
veritas-0.0.4 spec/unit/veritas/aggregate/standard_deviation/class_methods/finalize_spec.rb