-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestExperiment.java
More file actions
99 lines (73 loc) · 2.33 KB
/
TestExperiment.java
File metadata and controls
99 lines (73 loc) · 2.33 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package blang.inits;
import java.util.Arrays;
import org.eclipse.xtext.xbase.lib.Pair;
import blang.inits.GlobalArg;
import blang.inits.experiments.Experiment;
import blang.inits.experiments.ExperimentResults;
import blang.inits.experiments.tabwriters.TabularWriter;
import blang.inits.experiments.tabwriters.TabularWriterFactory;
import blang.inits.experiments.tabwriters.factories.CSV;
import blang.inits.experiments.tabwriters.factories.Spark;
public class TestExperiment extends Experiment
{
@Arg @DefaultValue("world!")
public String option;
@GlobalArg
public ExperimentResults result;
@Arg @DefaultValue({"--test", "123"})
public Custom c;
@Arg @DefaultValue("AnImpl")
public AnInter a;
public static class Custom
{
@Arg
int test;
}
@Implementations(AnImpl.class)
public static interface AnInter
{
}
public static class AnImpl implements AnInter
{
}
@Override
public void run()
{
System.out.println("Running");
result.getAutoClosedPrintWriter("test").append("Hello " + option);
{ // example of correct usage of default (command line provided) TabularWriter
TabularWriter csv = result.getTabularWriter("my-results");
for (int i = 0; i < 10; i++)
printSomeResults(csv.child("iteration", i));
}
{ // example of incorrect usage
TabularWriter csv = result.getTabularWriter("my-results");
for (int i = 0; i < 10; i++)
printSomeResults(csv.child("iteration", i));
try {
csv.write(Pair.of("label", "xx"));
System.out.println("SHOULD NOT GET HERE!");
}
catch (Exception e) {
System.out.println("error correctly caught: " + e);
}
}
for (TabularWriterFactory impl : Arrays.asList(new CSV(), new Spark()))
{
{ // example of correct usage of provided TabularWriter
TabularWriter csv = result.getTabularWriter("my-results-" + impl.getClass().getSimpleName(), impl);
for (int i = 0; i < 10; i++)
printSomeResults(csv.child("iteration", i));
}
}
}
private void printSomeResults(TabularWriter writer)
{
for (String label : new String[]{"one", "two"})
writer.write(Pair.of("label", label));
}
public static void main(String [] args)
{
Experiment.start(args);
}
}