Sha256: 9fba93628475c24e255f9d8a0bd59c056cf3044deec8588d4c2fda3a7980f8f9

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

describe Picky::Indexing::Bundle::Memory do

  before(:each) do
    @index            = Picky::Indexes::Memory.new :some_index
    @category         = Picky::Category.new :some_category, @index
    
    @partial_strategy = Picky::Generators::Partial::Substring.new :from => 1
    @exact            = described_class.new :some_name, @category, nil, @partial_strategy, nil
  end

  def generate_random_keys amount
    alphabet = ('a'..'z').to_a
    (1..amount).to_a.collect! do |n|
      Array.new(20).collect! { alphabet[rand(26)] }.join.to_sym
    end
  end
  def generate_random_ids amount
    (1..amount).to_a.collect! do |_|
      Array.new(rand(100)+5).collect! do |_|
        rand(5_000_000)
      end
    end
  end

  describe 'speed' do
    context 'medium arrays' do
      before(:each) do
        random_keys     = generate_random_keys 300
        random_ids      = generate_random_ids  300
        @exact.inverted = Hash[random_keys.zip(random_ids)]
      end
      it 'should be fast' do
        performance_of do
          @exact.generate_partial
        end.should < 0.1
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
picky-3.0.1 spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb
picky-3.0.0 spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb
picky-3.0.0.pre5 spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb
picky-3.0.0.pre4 spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb
picky-3.0.0.pre3 spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb
picky-3.0.0.pre2 spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb