-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBigIntegerProblemsTest.java
More file actions
executable file
·40 lines (35 loc) · 1.22 KB
/
Copy pathBigIntegerProblemsTest.java
File metadata and controls
executable file
·40 lines (35 loc) · 1.22 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
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Random;
import java.io.*;
import java.util.*;
import java.util.zip.CRC32;
import java.math.BigInteger;
public class BigIntegerProblemsTest {
private static final int SEED = 12345;
private static final BigInteger TWO = new BigInteger("2");
@Test public void testFibonacciSum() {
CRC32 check = new CRC32();
Random rng = new Random(SEED);
BigInteger curr = BigInteger.ONE;
for(int i = 0; i < 500; i++) {
List<BigInteger> result = BigIntegerProblems.fibonacciSum(curr);
for(BigInteger b: result) {
check.update(b.toString().getBytes());
}
curr = curr.add(new BigInteger("" + (rng.nextInt(5) + 1)));
curr = curr.multiply(TWO);
}
assertEquals(3283204958L, check.getValue());
}
@Test public void testSevenZero() {
CRC32 check = new CRC32();
for(int i = 2; i < 300; i++) {
BigInteger result = BigIntegerProblems.sevenZero(i);
check.update(result.toString().getBytes());
}
assertEquals(3791754529L, check.getValue());
}
}