-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTaskTests.java
More file actions
56 lines (44 loc) · 1.65 KB
/
Copy pathTaskTests.java
File metadata and controls
56 lines (44 loc) · 1.65 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
package tests;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BiFunction;
public class TaskTests {
/*******************************/
/* DO NOT TOUCH METHODS BELLOW */
/*******************************/
private final List <?> inputs;
private final Method method;
public TaskTests (Method method, List <?> inputs) {
this.method = method; this.inputs = inputs;
}
private final List <BiFunction <StreamTasksTests, StreamTasksTests, InvocationResult>> cases = new ArrayList <> ();
public TaskTests addCase (BiFunction <StreamTasksTests, StreamTasksTests, InvocationResult> caze) {
cases.add (caze);
return this;
}
public int getCasesNumber () {
return cases.size ();
}
public Method getMethod () {
return method;
}
public List <?> getInputs () {
return Collections.unmodifiableList (inputs);
}
public InvocationResult runTests (StreamTasksTests implementation, StreamTasksTests reference) {
final var stub = new InvocationResult (null, 0);
return cases.stream ().map (caze -> caze.apply (implementation, reference))
. reduce (stub, (a, b) -> {
if (a == stub && b != null) {
return b;
} else if (a != stub && b != null) {
b.addAnotherResult (a);
return b;
} else {
return a;
}
});
}
}