-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSumChecker.java
More file actions
31 lines (28 loc) · 1.01 KB
/
Copy pathSumChecker.java
File metadata and controls
31 lines (28 loc) · 1.01 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
import java.util.List;
import java.util.ListIterator;
/**
* @author Georgiy Korneev (kgeorgiy@kgeorgiy.info)
*/
public class SumChecker extends MainChecker {
public SumChecker(final String className) {
super(className);
}
public void testRandom(final long result, final List<String> args) {
for (final ListIterator<String> li = args.listIterator(); li.hasNext(); ) {
li.set(randomSpace() + li.next() + randomSpace());
}
for (final ListIterator<String> li = args.listIterator(); li.hasNext(); ) {
String next = li.next();
if (li.hasNext() && random.nextBoolean()) {
next += " " + randomSpace() + li.next();
li.remove();
li.previous();
li.set(next);
}
}
test(result, args.toArray(new String[args.size()]));
}
private String randomSpace() {
return random.nextBoolean() ? "" : " \t\n\u000B\u2029\f".charAt(random.nextInt(6)) + randomSpace();
}
}