|
6 | 6 | * %% |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted provided that the following conditions are met: |
9 | | - * |
| 9 | + * |
10 | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
11 | 11 | * this list of conditions and the following disclaimer. |
12 | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
13 | 13 | * this list of conditions and the following disclaimer in the documentation |
14 | 14 | * and/or other materials provided with the distribution. |
15 | | - * |
| 15 | + * |
16 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
17 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
26 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
27 | 27 | * #L% |
28 | 28 | */ |
| 29 | + |
29 | 30 | package org.scijava.ops; |
30 | 31 |
|
| 32 | +import java.lang.reflect.Type; |
| 33 | +import java.util.Arrays; |
| 34 | + |
31 | 35 | import org.junit.Test; |
| 36 | +import org.scijava.types.Nil; |
32 | 37 |
|
33 | 38 | 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 | + } |
38 | 82 | } |
0 commit comments