Sha256: 97e92560f4077f46aebc2e5bd762c957a8a04c02d9f9def3487bb14761970187

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

require 'spec_helper'

describe EratosteneSieve do

  describe '.nth_prime' do
    it 'should output the nth prime number' do
      EratosteneSieve.nth_prime(1).should be_eql(2)
      EratosteneSieve.nth_prime(2).should be_eql(3)
      EratosteneSieve.nth_prime(3).should be_eql(5)
      EratosteneSieve.nth_prime(4).should be_eql(7)
      EratosteneSieve.nth_prime(10).should be_eql(29)
      EratosteneSieve.nth_prime(20).should be_eql(71)
      EratosteneSieve.nth_prime(30).should be_eql(113)
      EratosteneSieve.nth_prime(100).should be_eql(541)
      EratosteneSieve.nth_prime(200).should be_eql(1223)
    end
  end

  describe '.prime_serie' do
    it 'should return ' do
      enumerator = EratosteneSieve.prime_serie
      serie = []
      (0..9).each { |i| serie << enumerator.next }
      serie.should == [1, 2, 3, 5, 7, 11, 13, 17, 19, 23]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eratostene_sieve-0.0.2.alpha spec/eratostene_sieve_spec.rb