Sha256: 4f33e22f6e23602ac49c0f8aa4a94d1f2e04b0b4645e322b77eb31cf0686f4cc

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

require File.expand_path('../spec_helper', File.dirname(__FILE__))
require 'gorillib/array/sorted_sample'

describe Array do
  describe '#sorted_median' do
    context 'with empty' do
      it 'returns an empty array' do
        [].sorted_sample(1).should be_empty
      end
    end

    context 'given an undersized array' do
      it 'does not return the same element more than once' do
        ("a".."z").to_a.sorted_sample(27).should == ("a".."z").to_a
      end
    end

    context 'given any array' do
      it ('returns a sample of the given size as close to evenly ' \
          'distributed over the array as possible') do
        sample = (1..100).to_a.sorted_sample(26)
        deltas = sample[0..-2].zip(sample[1..-1]).map{|a,b| b-a}
        deltas.max.should <= 4
        deltas.min.should >= 3
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gorillib-0.4.1pre spec/array/sorted_sample_spec.rb
gorillib-0.1.11 spec/array/sorted_sample_spec.rb