-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversalAlgorithmsTest.java
More file actions
executable file
·64 lines (56 loc) · 1.98 KB
/
Copy pathReversalAlgorithmsTest.java
File metadata and controls
executable file
·64 lines (56 loc) · 1.98 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
52
53
54
55
56
57
58
59
60
61
62
63
64
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 ReversalAlgorithmsTest {
private static final int SEED = 12345;
private static final int ROUNDS = 1000;
@Test public void testPancakeScramble() throws IOException {
CRC32 check = new CRC32();
BufferedReader fr = new BufferedReader(
new InputStreamReader(new FileInputStream("warandpeace.txt"), "UTF-8")
);
String line = fr.readLine();
while(line != null) {
String result = ReversalAlgorithms.pancakeScramble(line);
check.update(result.getBytes());
line = fr.readLine();
}
fr.close();
assertEquals(1606800991L, check.getValue());
}
@Test public void testReverseVowels() throws IOException {
CRC32 check = new CRC32();
BufferedReader fr = new BufferedReader(
new InputStreamReader(new FileInputStream("warandpeace.txt"), "UTF-8")
);
String line = fr.readLine();
while(line != null) {
String result = ReversalAlgorithms.reverseVowels(line);
check.update(result.getBytes());
line = fr.readLine();
}
fr.close();
assertEquals(3844894811L, check.getValue());
}
@Test public void testReverseAscendingSubarrays() {
Random rng = new Random(SEED);
CRC32 check = new CRC32();
for(int i = 0; i < ROUNDS; i++) {
int len = rng.nextInt(1000);
int[] a = new int[len];
for(int j = 0; j < len; j++) {
a[j] = rng.nextInt(1000000);
}
ReversalAlgorithms.reverseAscendingSubarrays(a);
for(int j = 0; j < len; j++) {
check.update(a[j]);
}
}
assertEquals(3118921076L, check.getValue());
}
}