Sha256: 6bf46776317d0885a99ecd1236d0d299558d036a2d70e44fac1f6cfe9bf2a0a5

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

describe Metrics::Statistics::UniformSample do
  before(:each) do
  end
  
  it "should have a size equal to the initialization parameter" do 
    sample = Metrics::Statistics::UniformSample.new(100)
    sample.size.should == 100
    
  end
  
  it "should allocate an array of the requested size" do
    sample = Metrics::Statistics::UniformSample.new(100)
    sample.values.length.should == 100
    
    sample.values.each do |value|
      value.should == 0
    end
  end
  
  it "should update at the end of the list" do
    sample = Metrics::Statistics::UniformSample.new(100)
    (1..100).each do |i|
      sample.update(i)
    end
    
    values = sample.values
    
    (0..99).each do |index|
      values[index].should == (index + 1)
    end
  end
  
  it "should update a random entry in the list when it's full" do
    
    sample = Metrics::Statistics::UniformSample.new(100)
    sample.should_receive(:rand).with(any_args()).and_return(50)

    (1..101).each do |i|
      sample.update(i)
    end
    
    values = sample.values
    
    (0..49).each do |index|
      values[index].should == (index + 1)
    end
    
    values[50].should == 101
    
    (51..99).each do |index|
      values[index].should == (index + 1)
    end
    
  end
  
  
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
ruby-metrics-0.9.4 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.9.3 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.9.2 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.9.1 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.9.0 spec/statistics/uniform_sample_spec.rb
yam-ruby-metrics-0.8.9 spec/statistics/uniform_sample_spec.rb
yam-ruby-metrics-0.8.8 spec/statistics/uniform_sample_spec.rb
yam-ruby-metrics-0.8.7 spec/statistics/uniform_sample_spec.rb
yam-ruby-metrics-0.8.6 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.8.6 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.8.5 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.8.0 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.7.0 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.6.0 spec/statistics/uniform_sample_spec.rb
ruby-metrics-0.5.0 spec/statistics/uniform_sample_spec.rb