Sha256: e649ab092af6622dd6e26ec6731bea0e5c622849e8c01f90ab1f7136ff3991f4

Contents?: true

Size: 963 Bytes

Versions: 7

Compression:

Stored size: 963 Bytes

Contents

$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'test_helper'

include SieveLab

class TestSieve < Test::Unit::TestCase

  def test_00_banner
    print "\nSieveLab"
  end
  
	# Compare list generated by sieve method with list from Wikipedia.  Test both the main
	# version (sieve) and the simple prototype that iterates until the worklist is empty.
	
  def test_01_first_25
    expected = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
		assert_equal expected, sieve(100)
		assert_equal expected, proto_sieve(100)
  end

	# Check length of list generated by sieve with expected number of primes (also from Wikipedia).
	# pi[i] is the number of primes less than 10**i.  Note: calling sieve(n) with n less than 2
	# should quietly return an empty list.

  def test_02_pi
    pi = [0, 4, 25, 168, 1229]          # 9592
    for i in 0..(pi.length-1)
      assert_equal pi[i], sieve(10**i).length
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rubylabs-0.7.5 test/sieve_test.rb
rubylabs-0.7.4 test/sieve_test.rb
rubylabs-0.7.3 test/sieve_test.rb
rubylabs-0.7.2 test/sieve_test.rb
rubylabs-0.7.1 test/sieve_test.rb
rubylabs-0.7.0 test/sieve_test.rb
rubylabs-0.6.4 test/sieve_test.rb