Sha256: 21b521188d0f183def46e27d3a39b9b2d124782c906b9ba8787da4df2b82f969

Contents?: true

Size: 884 Bytes

Versions: 4

Compression:

Stored size: 884 Bytes

Contents

# encoding: utf-8

RSpec.describe Benchmark::Perf, 'arithmetic' do
  context '#average' do
    it "calculates average without measurements" do
      expect(Benchmark::Perf.average([])).to eq(0)
    end

    it "calculates average with measurements" do
      expect(Benchmark::Perf.average([1,2,3])).to eq(2.0)
    end
  end

  context '#variance' do
    it "calculates variance of no measurements" do
      expect(Benchmark::Perf.variance([])).to eq(0)
    end

    it "calculates variance of measurements" do
      expect(Benchmark::Perf.variance([1,2,3])).to eq(2.to_f/3)
    end
  end

  context '#std_dev' do
    it "calculates standard deviation of no measurements" do
      expect(Benchmark::Perf.std_dev([])).to eq(0)
    end

    it "calculates standard deviation of measurements" do
      expect(Benchmark::Perf.std_dev([1,2,3])).to eq(Math.sqrt(2.to_f/3))
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
benchmark-perf-0.4.0 spec/unit/arithmetic_spec.rb
benchmark-perf-0.3.0 spec/unit/arithmetic_spec.rb
benchmark-perf-0.2.1 spec/unit/arithmetic_spec.rb
benchmark-perf-0.2.0 spec/unit/arithmetic_spec.rb