-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimesTest.java
More file actions
executable file
·45 lines (39 loc) · 1.2 KB
/
Copy pathPrimesTest.java
File metadata and controls
executable file
·45 lines (39 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.*;
import java.util.*;
import java.util.zip.CRC32;
public class PrimesTest {
@Test public void isPrimeTest() {
CRC32 check = new CRC32();
for(int k = 0; k < 10_000_000; k++) {
if(Primes.isPrime(k)) { check.update(k); }
}
assertEquals(783904569L, check.getValue());
}
@Test public void kthPrimeTest() {
CRC32 check = new CRC32();
for(int k = 0; k < 30_000; k++) {
check.update(Primes.kthPrime(k));
}
assertEquals(3080752681L, check.getValue());
}
@Test public void factorizeTest() {
CRC32 check = new CRC32();
for(int k = 2; k < 500_000; k++) {
List<Integer> factors = Primes.factorize(k);
int prod = 1;
int prev = 0;
for(int f: factors) {
assertTrue(f >= prev);
prev = f;
prod = prod * f;
check.update(f);
}
assertEquals(k, prod);
}
assertEquals(2607517043L, check.getValue());
}
}