$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