Sha256: 955d70eababff5946e9ae864e77c7db65d5b36515cf486c45708bf25ff1f4e63

Contents?: true

Size: 782 Bytes

Versions: 24

Compression:

Stored size: 782 Bytes

Contents

require 'spec_helper'

describe Infobar::Timer do
  let :timer do
    described_class.new
  end

  it 'has default average time of 0.0' do
    expect(timer.average_time).to eq 0.0
  end

  it 'has default rate of 0.0' do
    expect(timer.rate).to eq 0.0
  end

  it 'can be added to' do
    now = Time.now
    timer.add(now, 2)
    expect(timer.average_time).to eq 0.0
    expect(timer.rate).to eq 0.0
    expect(timer.n).to eq 1
    timer.add(now + 2, 4)
    expect(timer.average_time).to be_within(1e-3).of(3.0 / 4)
    expect(timer.rate).to be_within(1e-3).of(4 / 3.0)
    expect(timer.n).to eq 2
    timer.add(now + 3, 1)
    expect(timer.average_time).to be_within(1e-3).of(0.8333)
    expect(timer.rate).to be_within(1e-3).of(1 / 0.8333)
    expect(timer.n).to eq 3
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
infobar-0.8.1 spec/infobar/timer_spec.rb
infobar-0.8.0 spec/infobar/timer_spec.rb
infobar-0.7.4 spec/infobar/timer_spec.rb
infobar-0.7.2 spec/infobar/timer_spec.rb
infobar-0.7.1 spec/infobar/timer_spec.rb
infobar-0.7.0 spec/infobar/timer_spec.rb
infobar-0.6.2 spec/infobar/timer_spec.rb
infobar-0.6.1 spec/infobar/timer_spec.rb
infobar-0.6.0 spec/infobar/timer_spec.rb
infobar-0.5.1 spec/infobar/timer_spec.rb
infobar-0.5.0 spec/infobar/timer_spec.rb
infobar-0.4.0 spec/infobar/timer_spec.rb
infobar-0.3.0 spec/infobar/timer_spec.rb
infobar-0.2.0 spec/infobar/timer_spec.rb
infobar-0.1.1 spec/infobar/timer_spec.rb
infobar-0.1.0 spec/infobar/timer_spec.rb
infobar-0.0.7 spec/infobar/timer_spec.rb
infobar-0.0.6 spec/infobar/timer_spec.rb
infobar-0.0.5 spec/infobar/timer_spec.rb
infobar-0.0.4 spec/infobar/timer_spec.rb