]> gitweb.factorcode.org Git - factor.git/blob - basis/math/primes/erato/erato-tests.factor
c68b35b655d6e14977b7ed88674813c5b93f4847
[factor.git] / basis / math / primes / erato / erato-tests.factor
1 USING: fry kernel math math.bitwise math.primes.erato
2 math.ranges sequences tools.test ;
3
4 { B{ 255 251 247 126 } } [ 100 sieve ] unit-test
5 [ 1 100 sieve marked-prime? ] [ bounds-error? ] must-fail-with
6 [ 120 100 sieve marked-prime? ] [ bounds-error? ] must-fail-with
7 { f } [ 119 100 sieve marked-prime? ] unit-test
8 { t } [ 113 100 sieve marked-prime? ] unit-test
9
10 ! There are 25997 primes below 300000. 1 must be removed and 3 5 7 added.
11 { 25997 } [ 299999 sieve [ bit-count ] map-sum 2 + ] unit-test
12
13 ! Check sieve array length logic by making sure we get the right
14 ! end-point for numbers with all possibilities mod 30. If something
15 ! were to go wrong, we'd get a bounds-error.
16 { } [ 2 100 [a..b] [ dup sieve marked-prime? drop ] each ] unit-test
17
18 { t } [
19     { 2 3 5 7 11 13 } 100 sieve '[ _ marked-prime? ] all?
20 ] unit-test
21 { t } [
22     { 4 6 8 9 10 12 } 100 sieve '[ _ marked-prime? not ] all?
23 ] unit-test