Sha256: f889d5ba1b791ec81620859d19cda0dacdb995644c15c17615d6a445c12b76b5

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

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)
  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
	# raises an exception ("NoMethodError: undefined method `<' for nil:NilClass")

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rubylabs-1.0.2 test/sieve_test.rb
rubylabs-1.0.1 test/sieve_test.rb
rubylabs-1.0.0 test/sieve_test.rb
rubylabs-0.9.8 test/sieve_test.rb
rubylabs-0.9.7 test/sieve_test.rb
rubylabs-0.9.6 test/sieve_test.rb
rubylabs-0.9.5 test/sieve_test.rb
rubylabs-0.9.4 test/sieve_test.rb
rubylabs-0.9.3 test/sieve_test.rb
rubylabs-0.9.2 test/sieve_test.rb
rubylabs-0.9.1 test/sieve_test.rb
rubylabs-0.9.0 test/sieve_test.rb
rubylabs-0.8.3 test/sieve_test.rb
rubylabs-0.8.2 test/sieve_test.rb