quick-is-prime
Advanced tools
Comparing version 1.0.6 to 1.0.7
{ | ||
"name": "quick-is-prime", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Test if a number is prime in constant time, using a cached Sieve of Eratosthenes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -23,10 +23,10 @@ # quick-is-prime | ||
// Simple examples | ||
console.log(isPrime(47)); // true | ||
console.log(isPrime(48)); // false | ||
console.log(isPrime(61)); // true | ||
console.log(isPrime(100)); // false | ||
isPrime(47) // => true | ||
isPrime(48) // => false | ||
isPrime(61) // => true | ||
isPrime(100) // => false | ||
// More challenging examples | ||
console.log(isPrime(9998903)) // true, takes 1.5 seconds | ||
console.log(isPrime(9893899)) // true, takes less than a millisecond | ||
isPrime(9998903) // => true, takes 1.5 seconds | ||
isPrime(9893899) // => true, takes less than a millisecond | ||
``` | ||
@@ -33,0 +33,0 @@ |
18
test.js
@@ -17,7 +17,10 @@ /*global describe,it*/ | ||
it('works for larger numbers too', function () { | ||
it('can test a 7-digit numbers in under two seconds', function () { | ||
var start = process.hrtime(); | ||
assert(isPrime(9998903) === true); | ||
var durationInNanoseconds = process.hrtime(start)[1]; | ||
assert(durationInNanoseconds < 2000000000); | ||
}); | ||
it('takes less than a millisecond to test numbers less than the highest already tested', function () { | ||
it('takes under a millisecond for numbers less than the highest already tested', function () { | ||
var start = process.hrtime(); | ||
@@ -28,2 +31,13 @@ assert(isPrime(9893899) === true); | ||
}); | ||
it('returns false for 0, 1, and negative numbers', function () { | ||
assert(isPrime(0) === false); | ||
assert(isPrime(1) === false); | ||
assert(isPrime(-3) === false); | ||
}); | ||
it('returns false for strings', function () { | ||
assert(isPrime('hello') === false); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4082
46