-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRunTest.java
More file actions
328 lines (289 loc) · 9.72 KB
/
RunTest.java
File metadata and controls
328 lines (289 loc) · 9.72 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
package org.scijava.ops;
import java.util.function.BiFunction;
import java.util.function.Function;
import org.junit.Assert;
import org.junit.Test;
import org.scijava.ops.core.OpCollection;
import org.scijava.ops.core.computer.BiComputer;
import org.scijava.ops.core.computer.Computer;
import org.scijava.ops.core.computer.Computer3;
import org.scijava.ops.core.computer.Computer4;
import org.scijava.ops.core.computer.Computer5;
import org.scijava.ops.core.function.Function3;
import org.scijava.ops.core.function.Function4;
import org.scijava.ops.core.function.Function5;
import org.scijava.ops.core.inplace.BiInplaceFirst;
import org.scijava.ops.core.inplace.BiInplaceSecond;
import org.scijava.ops.core.inplace.Inplace;
import org.scijava.ops.core.inplace.Inplace3First;
import org.scijava.ops.core.inplace.Inplace4First;
import org.scijava.ops.core.inplace.Inplace5First;
import org.scijava.param.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.struct.ItemIO;
@Plugin(type = OpCollection.class)
public class RunTest extends AbstractTestEnvironment {
// FUNCTIONS
@OpField(names = "test.Function")
@Parameter(key = "num1")
@Parameter(key = "sum", itemIO = ItemIO.OUTPUT)
public static final Function<Double, Double> testFunction = (num1) -> num1 + 1;
@Test
public void testRunFunction() {
Double answer = (Double) ops.run("test.Function", 1.0);
Assert.assertEquals(2.0, answer, 0);
}
@OpField(names = "test.BiFunction")
@Parameter(key = "num1")
@Parameter(key = "num2")
@Parameter(key = "sum", itemIO = ItemIO.OUTPUT)
public static final BiFunction<Double, Double, Double> testBiFunction = (num1, num2) -> num1 + num2;
@Test
public void testRunBiFunction() {
Double answer = (Double) ops.run("test.BiFunction", 1.0, 1.0);
Assert.assertEquals(2.0, answer, 0);
}
@OpField(names = "test.Function3")
@Parameter(key = "num1")
@Parameter(key = "num2")
@Parameter(key = "num3")
@Parameter(key = "sum", itemIO = ItemIO.OUTPUT)
public static final Function3<Double, Double, Double, Double> testFunction3 = (num1, num2, num3) -> num1 + num2
+ num3;
@Test
public void testRunFunction3() {
Double answer = (Double) ops.run("test.Function3", 1.0, 1.0, 1.0);
Assert.assertEquals(3.0, answer, 0);
}
@OpField(names = "test.Function4")
@Parameter(key = "num1")
@Parameter(key = "num2")
@Parameter(key = "num3")
@Parameter(key = "num4")
@Parameter(key = "sum", itemIO = ItemIO.OUTPUT)
public static final Function4<Double, Double, Double, Double, Double> testFunction4 = (num1, num2, num3,
num4) -> num1 + num2 + num3 + num4;
@Test
public void testRunFunction4() {
Double answer = (Double) ops.run("test.Function4", 1.0, 1.0, 1.0, 1.0);
Assert.assertEquals(4.0, answer, 0);
}
@OpField(names = "test.Function5")
@Parameter(key = "num1")
@Parameter(key = "num2")
@Parameter(key = "num3")
@Parameter(key = "num4")
@Parameter(key = "num5")
@Parameter(key = "sum", itemIO = ItemIO.OUTPUT)
public static final Function5<Double, Double, Double, Double, Double, Double> testFunction5 = (num1, num2, num3,
num4, num5) -> num1 + num2 + num3 + num4 + num5;
@Test
public void testRunFunction5() {
Double answer = (Double) ops.run("test.Function5", 1.0, 1.0, 1.0, 1.0, 1.0);
Assert.assertEquals(5.0, answer, 0);
}
// COMPUTERS
@OpField(names = "test.Computer")
@Parameter(key = "arr1")
@Parameter(key = "arr2", itemIO = ItemIO.BOTH)
public static final Computer<double[], double[]> testComputer = (arr1, out) -> {
for (int i = 0; i < arr1.length; i++) {
out[i] = arr1[i] * 2;
}
};
@Test
public void testRunComputer() {
double[] arr1 = { 1, 2, 3 };
double[] out = new double[3];
ops.run("test.Computer", arr1, out);
Assert.assertArrayEquals(new double[] { 2, 4, 6 }, out, 0);
}
@OpField(names = "test.BiComputer")
@Parameter(key = "arr1")
@Parameter(key = "arr2")
@Parameter(key = "out", itemIO = ItemIO.BOTH)
public static final BiComputer<double[], double[], double[]> testBiComputer = (arr1, arr2, out) -> {
for (int i = 0; i < arr1.length; i++) {
out[i] = arr1[i] + arr2[i];
}
};
@Test
public void testRunBiComputer() {
double[] arr1 = { 1, 2, 3 };
double[] arr2 = { 1, 2, 3 };
double[] out = new double[3];
ops.run("test.BiComputer", arr1, arr2, out);
Assert.assertArrayEquals(new double[] { 2, 4, 6 }, out, 0);
}
@OpField(names = "test.Computer3")
@Parameter(key = "arr1")
@Parameter(key = "arr2")
@Parameter(key = "arr3")
@Parameter(key = "out", itemIO = ItemIO.BOTH)
public static final Computer3<double[], double[], double[], double[]> testComputer3 = (arr1, arr2, arr3, out) -> {
for (int i = 0; i < arr1.length; i++) {
out[i] = arr1[i] + arr2[i] + arr3[i];
}
};
@Test
public void testRunComputer3() {
double[] arr1 = { 1, 2, 3 };
double[] arr2 = { 1, 2, 3 };
double[] arr3 = { 1, 2, 3 };
double[] out = new double[3];
ops.run("test.Computer3", arr1, arr2, arr3, out);
Assert.assertArrayEquals(new double[] { 3, 6, 9 }, out, 0);
}
@OpField(names = "test.Computer4")
@Parameter(key = "arr1")
@Parameter(key = "arr2")
@Parameter(key = "arr3")
@Parameter(key = "arr4")
@Parameter(key = "out", itemIO = ItemIO.BOTH)
public static final Computer4<double[], double[], double[], double[], double[]> testComputer4 = (arr1, arr2, arr3,
arr4, out) -> {
for (int i = 0; i < arr1.length; i++) {
out[i] = arr1[i] + arr2[i] + arr3[i] + arr4[i];
}
};
@Test
public void testRunComputer4() {
double[] arr1 = { 1, 2, 3 };
double[] arr2 = { 1, 2, 3 };
double[] arr3 = { 1, 2, 3 };
double[] arr4 = { 1, 2, 3 };
double[] out = new double[3];
ops.run("test.Computer4", arr1, arr2, arr3, arr4, out);
Assert.assertArrayEquals(new double[] { 4, 8, 12 }, out, 0);
}
@OpField(names = "test.Computer5")
@Parameter(key = "arr1")
@Parameter(key = "arr2")
@Parameter(key = "arr3")
@Parameter(key = "arr4")
@Parameter(key = "arr5")
@Parameter(key = "out", itemIO = ItemIO.BOTH)
public static final Computer5<double[], double[], double[], double[], double[], double[]> testComputer5 = (arr1,
arr2, arr3, arr4, arr5, out) -> {
for (int i = 0; i < arr1.length; i++) {
out[i] = arr1[i] + arr2[i] + arr3[i] + arr4[i] + arr5[i];
}
};
@Test
public void testRunComputer5() {
double[] arr1 = { 1, 2, 3 };
double[] arr2 = { 1, 2, 3 };
double[] arr3 = { 1, 2, 3 };
double[] arr4 = { 1, 2, 3 };
double[] arr5 = { 1, 2, 3 };
double[] out = new double[3];
ops.run("test.Computer5", arr1, arr2, arr3, arr4, arr5, out);
Assert.assertArrayEquals(new double[] { 5, 10, 15 }, out, 0);
}
// INPLACES
@OpField(names = "test.Inplace")
@Parameter(key = "io", itemIO = ItemIO.BOTH)
public static final Inplace<double[]> testInplace = (io) -> {
for (int i = 0; i < io.length; i++)
io[i] *= 2;
};
@Test
public void testRunInplace() {
double[] io = { 1, 2, 3 };
ops.run("test.Inplace", io);
Assert.assertArrayEquals(new double[] { 2, 4, 6 }, io, 0);
}
@OpField(names = "test.BiInplaceFirst")
@Parameter(key = "io", itemIO = ItemIO.BOTH)
@Parameter(key = "in2")
public static final BiInplaceFirst<double[], double[]> testBiInplaceFirst = (io, in2) -> {
for (int i = 0; i < io.length; i++)
io[i] += in2[i];
};
@Test
public void testRunBiInplaceFirst() {
double[] io = { 1, 2, 3 };
double[] in2 = { 1, 2, 3 };
ops.run("test.BiInplaceFirst", io, in2);
Assert.assertArrayEquals(new double[] { 2, 4, 6 }, io, 0);
}
@OpField(names = "test.BiInplaceSecond")
@Parameter(key = "in1")
@Parameter(key = "io", itemIO = ItemIO.BOTH)
public static final BiInplaceSecond<double[], double[]> testBiInplaceSecond = (in1, io) -> {
for (int i = 0; i < io.length; i++)
io[i] *= in1[i];
};
@Test
public void testRunBiInplaceSecond() {
double[] in1 = { 1, 2, 3 };
double[] io = { 1, 2, 3 };
ops.run("test.BiInplaceSecond", in1, io);
Assert.assertArrayEquals(new double[] { 1, 4, 9 }, io, 0);
}
@OpField(names = "test.Inplace3First")
@Parameter(key = "io", itemIO = ItemIO.BOTH)
@Parameter(key = "in2")
@Parameter(key = "in3")
public static final Inplace3First<double[], double[], double[]> testInplace3First = (io, in2, in3) -> {
for (int i = 0; i < io.length; i++) {
io[i] += in2[i];
io[i] += in3[i];
}
};
@Test
public void testRunInplace3First() {
double[] io = { 1, 2, 3 };
double[] in2 = { 1, 2, 3 };
double[] in3 = { 1, 2, 3 };
ops.run("test.Inplace3First", io, in2, in3);
Assert.assertArrayEquals(new double[] { 3, 6, 9 }, io, 0);
}
@OpField(names = "test.Inplace4First")
@Parameter(key = "io", itemIO = ItemIO.BOTH)
@Parameter(key = "in2")
@Parameter(key = "in3")
@Parameter(key = "in4")
public static final Inplace4First<double[], double[], double[], double[]> testInplace4First = (io, in2, in3,
in4) -> {
for (int i = 0; i < io.length; i++) {
io[i] += in2[i];
io[i] += in3[i];
io[i] += in4[i];
}
};
@Test
public void testRunInplace4First() {
double[] io = { 1, 2, 3 };
double[] in2 = { 1, 2, 3 };
double[] in3 = { 1, 2, 3 };
double[] in4 = { 1, 2, 3 };
ops.run("test.Inplace4First", io, in2, in3, in4);
Assert.assertArrayEquals(new double[] { 4, 8, 12 }, io, 0);
}
@OpField(names = "test.Inplace5First")
@Parameter(key = "io", itemIO = ItemIO.BOTH)
@Parameter(key = "in2")
@Parameter(key = "in3")
@Parameter(key = "in4")
@Parameter(key = "in5")
public static final Inplace5First<double[], double[], double[], double[], double[]> testInplace5First = (io, in2, in3,
in4, in5) -> {
for (int i = 0; i < io.length; i++) {
io[i] += in2[i];
io[i] += in3[i];
io[i] += in4[i];
io[i] += in5[i];
}
};
@Test
public void testRunInplace5First() {
double[] io = { 1, 2, 3 };
double[] in2 = { 1, 2, 3 };
double[] in3 = { 1, 2, 3 };
double[] in4 = { 1, 2, 3 };
double[] in5 = { 1, 2, 3 };
ops.run("test.Inplace5First", io, in2, in3, in4, in5);
Assert.assertArrayEquals(new double[] { 5, 10, 15 }, io, 0);
}
}