-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBaseTest.java
More file actions
73 lines (57 loc) · 1.87 KB
/
BaseTest.java
File metadata and controls
73 lines (57 loc) · 1.87 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
65
66
67
68
69
70
71
72
73
package expression;
import base.Asserts;
import base.TestCounter;
import java.util.*;
/**
* @author Georgiy Korneev (kgeorgiy@kgeorgiy.info)
*/
public abstract strictfp class BaseTest extends Asserts {
protected final Random random = new Random(7240958270485L);
protected final TestCounter counter = new TestCounter();
protected BaseTest() {
Locale.setDefault(Locale.US);
checkAssert(getClass());
}
protected <T> T random(final List<T> variants) {
return variants.get(random.nextInt(variants.size()));
}
protected int randomInt(final int n) {
return random.nextInt(n);
}
public void run() {
System.out.println("=== Testing " + getClass().getSimpleName());
test();
counter.printStatus(getClass());
}
protected abstract void test();
@SafeVarargs
protected static <T> List<T> list(final T... items) {
return new ArrayList<>(Arrays.asList(items));
}
protected static void addRange(final List<Integer> values, final int d, final int c) {
for (int i = -d; i <= d; i++) {
values.add(c + i);
}
}
public static final class Op<T> {
public final String name;
public final T f;
private Op(final String name, final T f) {
this.name = name;
this.f = f;
}
}
public static <T> Op<T> op(final String name, final T f) {
return new Op<>(name, f);
}
public static int mode(final String[] args, final String... modes) {
if (args.length != 1) {
throw error("Single argument expected. Supported modes: %s", Arrays.asList(modes));
}
final int index = List.of(modes).indexOf(args[0]);
if (index < 0) {
throw error("Invalid mode '%s'. Supported moves: %s", args[0], Arrays.asList(modes));
}
return index;
}
}