JDK 9 RFR of 8026236: Add PrimeTest for BigInteger [TEST-ONLY]
paul.sandoz at oracle.com
Wed Apr 23 10:25:27 UTC 2014
On Apr 23, 2014, at 1:48 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
> Issue: https://bugs.openjdk.java.net/browse/JDK-8026236
> Patch: http://cr.openjdk.java.net/~bpb/8026236/webrev.00/
> This test provides a rudimentary verification of isProbablePrime() by:
> 1 - checking that the first 100000 primes are correctly identified as probably prime
> 2 - checking that a random sample of positive integers does not reveal non-prime numbers which test as prime
Note that the Stream obtained from br.lines will not close the underlying file, since it did not create the resource. You need to place the BufferedReader in the try.
> The test allows for specification of an alternate source file of prime numbers if one wants to run it by hand. The file of primes included in the patch was limited to 100000 values in the interest of keeping the file size small.
250k seems reasonable, but i don't know if there will be objections even to that size. Ideally it would be nice to download on demand to some separate repository and cached, but we really don't have the infrastructure in place for that (it would the same repository that could be used to publish JDK builds/images to be accessed by test machines).
> I think that the range of random numbers used for the non-prime portion of the test (currently [0,100000)) needs to be reexamined, but I wanted to throw this out there for discussion as-is.
Why not range from [2, upperBound) ?
long falsePositives = IntStream.range(0, upperBound)
.filter(bi -> !primes.contains(bi))
.filter(bi -> bi.isProbablePrime(certainty))
Otherwise for better random sampling i recommend using SplittableRandom. Generally i don't like adding non-determinism to tests as it makes it very tricky to track down errors.
> I’ve extended the use of the j.u.stream API to the entire test as recommended by Paul in http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-October/021859.html.
More information about the core-libs-dev