-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMathTest.java
More file actions
executable file
·51 lines (42 loc) · 1.34 KB
/
Copy pathGameMathTest.java
File metadata and controls
executable file
·51 lines (42 loc) · 1.34 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
46
47
48
49
50
51
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;
public class GameMathTest {
private void printTrues(boolean[] a) {
for(int i = 0; i < a.length; i++) {
if(a[i]) { System.out.print(i + " "); }
}
System.out.println("");
}
@Test public void testSubtractSquareThousand() {
test(1000, 4122798422L, 0);
}
@Test public void testSubtractSquareMillion() {
test(1_000_000, 1504185187L, 0);
}
@Test public void testSubtractSquareTenMillion() {
test(10_000_000, 3315207453L, 0);
}
@Test public void testSumOfTwoDistinctSquaresThousand() {
test(1000, 4110419952L, 1);
}
@Test public void testSumOfTwoDistinctSquaresMillion() {
test(1_000_000, 2362619161L, 1);
}
private void test(int n, long expected, int mode) {
CRC32 check = new CRC32();
boolean[] result;
if(mode == 0) { result = GameMath.subtractSquare(n); }
else { result = GameMath.sumOfTwoDistinctSquares(n); }
//printTrues(result);
for(int i = 0; i < n; i++) {
check.update(result[i] ? i : 0);
}
assertEquals(expected, check.getValue());
}
}