Skip to content

Commit 7162058

Browse files
ctruedengselzer
authored andcommitted
WIP: initial unit test for function + computer matching
1 parent ecd6698 commit 7162058

6 files changed

Lines changed: 127 additions & 10 deletions

File tree

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191

9292
<license.licenseName>bsd_2</license.licenseName>
9393
<license.copyrightOwners>SciJava Ops developers.</license.copyrightOwners>
94+
<scijava-common.version>2.75.0-type-service-SNAPSHOT</scijava-common.version>
95+
<enforcer.skip>true</enforcer.skip>
9496
</properties>
9597

9698
<dependencies>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.scijava.ops;
2+
3+
@FunctionalInterface
4+
public interface BinaryComputerOp<I1, I2, O> {
5+
void compute( I1 in1, I2 in2, O out );
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.scijava.ops;
2+
3+
import java.util.function.BiFunction;
4+
5+
@FunctionalInterface
6+
public interface BinaryFunctionOp<I1, I2, O> extends BiFunction<I1, I2, O> {
7+
}

src/main/java/org/scijava/ops/Main.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,26 @@
2828
*/
2929
package org.scijava.ops;
3030

31-
public class Main {
32-
public static void main(String... args) {
33-
System.out.println("Hello");
34-
}
31+
import java.io.IOException;
32+
33+
import org.scijava.parse.eval.EvaluatorConsole;
34+
35+
/**
36+
* Launches a console-based, Ops-driven expression evaluator.
37+
*
38+
* @author Curtis Rueden
39+
* @see EvaluatorConsole
40+
*/
41+
public final class Main {
42+
43+
private Main() {
44+
// Prevent instantiation of utility class.
45+
}
46+
47+
// -- Main method --
48+
49+
public static void main(final String[] args) throws IOException {
50+
System.out.println("blah");
51+
}
52+
3553
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* #%L
3+
* SciJava Operations: a framework for reusable algorithms.
4+
* %%
5+
* Copyright (C) 2018 SciJava developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package org.scijava.ops;
30+
31+
import org.scijava.service.SciJavaService;
32+
33+
/**
34+
* Interface for services that manage and execute ops.
35+
*
36+
* @author Curtis Rueden
37+
*/
38+
public interface OpService extends SciJavaService {
39+
// NB: Marker interface.
40+
}

src/test/java/org/scijava/ops/OpsTest.java

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
* %%
77
* Redistribution and use in source and binary forms, with or without
88
* modification, are permitted provided that the following conditions are met:
9-
*
9+
*
1010
* 1. Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
1212
* 2. Redistributions in binary form must reproduce the above copyright notice,
1313
* this list of conditions and the following disclaimer in the documentation
1414
* and/or other materials provided with the distribution.
15-
*
15+
*
1616
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1717
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1818
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -26,13 +26,57 @@
2626
* POSSIBILITY OF SUCH DAMAGE.
2727
* #L%
2828
*/
29+
2930
package org.scijava.ops;
3031

32+
import java.lang.reflect.Type;
33+
import java.util.Arrays;
34+
3135
import org.junit.Test;
36+
import org.scijava.types.Nil;
3237

3338
public class OpsTest {
34-
@Test
35-
public void testOps() {
36-
System.out.println("Hello");
37-
}
39+
40+
@Test
41+
public void testOps() {
42+
final String opName = "math.add";
43+
44+
final Nil<Double> nilDouble = new Nil<Double>() {};
45+
final Type[] inTypes = { nilDouble.getType(), nilDouble.getType() };
46+
final Type[] outTypes = { nilDouble.getType() };
47+
48+
// look up a function: Double result = math.add(Double v1, Double v2)
49+
final BinaryFunctionOp<Double, Double, Double> function = find( //
50+
opName, //
51+
new Nil<BinaryFunctionOp<Double, Double, Double>>()
52+
{}, //
53+
inTypes, //
54+
outTypes //
55+
);
56+
// execute the function
57+
final double answer = function.apply(1.0, 2.0);
58+
System.out.println("Function answer = " + answer);
59+
60+
// look up a computer: math.add(BOTH double[] result, double[] v1, double[]
61+
// v2)
62+
final BinaryComputerOp<double[], double[], double[]> computer = find( //
63+
opName, //
64+
new Nil<BinaryComputerOp<double[], double[], double[]>>()
65+
{}, //
66+
inTypes, //
67+
outTypes //
68+
);
69+
final double[] a1 = { 3, 5, 7 };
70+
final double[] a2 = { 2, 4, 9 };
71+
final double[] result = new double[a2.length];
72+
computer.compute(a1, a2, result);
73+
System.out.println("Computer result = " + Arrays.toString(result));
74+
}
75+
76+
private <T> T find(final String opName, final Nil<T> opType,
77+
final Type[] inTypes, final Type[] outTypes)
78+
{
79+
// TODO
80+
return null;
81+
}
3882
}

0 commit comments

Comments
 (0)