Search in sources :

Example 6 with Module

use of org.scijava.module.Module in project imagej-ops by imagej.

the class CachedOpEnvironment method otherArgs.

/**
 * Gets the given {@link Op} instance's argument value, starting at the
 * specified offset.
 */
private Object[] otherArgs(final Op op, final int offset) {
    final CommandInfo cInfo = info(op).cInfo();
    final Module module = cInfo.createModule(op);
    final ArrayList<Object> args = new ArrayList<>();
    int i = 0;
    for (final ModuleItem<?> input : cInfo.inputs()) {
        if (i++ >= offset)
            args.add(input.getValue(module));
    }
    return args.toArray();
}
Also used : CommandInfo(org.scijava.command.CommandInfo) ArrayList(java.util.ArrayList) Module(org.scijava.module.Module)

Example 7 with Module

use of org.scijava.module.Module in project imagej-ops by imagej.

the class OpMatchingServiceTest method testOptionalParams.

/**
 * Tests support for matching when there are optional parameters.
 */
@Test
public void testOptionalParams() {
    Module m;
    try {
        m = optionalParamsModule(1, 2, 3, 4, 5, 6, 7);
        fail("Expected IllegalArgumentException for 7 args");
    } catch (final IllegalArgumentException exc) {
    // NB: Expected.
    }
    m = optionalParamsModule(1, 2, 3, 4, 5, 6);
    assertValues(m, 1, 2, 3, 4, 5, 6, -7);
    m = optionalParamsModule(1, 2, 3, 4, 5);
    assertValues(m, 1, 2, 3, 4, -5, 5, -7);
    m = optionalParamsModule(1, 2, 3, 4);
    assertValues(m, 1, 2, 3, -4, -5, 4, -7);
    m = optionalParamsModule(1, 2, 3);
    assertValues(m, 1, -2, 2, -4, -5, 3, -7);
    try {
        m = optionalParamsModule(1, 2);
        fail("Expected IllegalArgumentException for 2 args");
    } catch (final IllegalArgumentException exc) {
    // NB: Expected.
    }
}
Also used : Module(org.scijava.module.Module) Test(org.junit.Test)

Example 8 with Module

use of org.scijava.module.Module in project imagej-ops by imagej.

the class OpMatchingServiceTest method testFindMatch.

/**
 * Tests {@link OpMatchingService#findMatch}.
 */
@Test
public void testFindMatch() {
    final DoubleType value = new DoubleType(123.456);
    final Module moduleByName = matcher.findMatch(ops, OpRef.create("test.nan", value)).getModule();
    assertSame(value, moduleByName.getInput("arg"));
    assertFalse(Double.isNaN(value.get()));
    moduleByName.run();
    assertTrue(Double.isNaN(value.get()));
    value.set(987.654);
    final Module moduleByType = matcher.findMatch(ops, OpRef.create(NaNOp.class, value)).getModule();
    assertSame(value, moduleByType.getInput("arg"));
    assertFalse(Double.isNaN(value.get()));
    moduleByType.run();
    assertTrue(Double.isNaN(value.get()));
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) Module(org.scijava.module.Module) Test(org.junit.Test)

Example 9 with Module

use of org.scijava.module.Module in project imagej-ops by imagej.

the class OpMatchingServiceTest method assertMatches.

private void assertMatches(final String name, Class<?>... opTypes) {
    final List<OpCandidate> candidates = matcher.findCandidates(ops, OpRef.create(name));
    final List<OpCandidate> matches = matcher.filterMatches(candidates);
    assertEquals(opTypes.length, matches.size());
    for (int i = 0; i < opTypes.length; i++) {
        final Module m = matches.get(i).getModule();
        assertSame(opTypes[i], m.getDelegateObject().getClass());
    }
}
Also used : Module(org.scijava.module.Module)

Example 10 with Module

use of org.scijava.module.Module in project imagej-ops by imagej.

the class OpServiceTest method testModuleByName.

/**
 * Tests {@link OpService#module(Class, Object...)}.
 */
@Test
public void testModuleByName() {
    final DoubleType value = new DoubleType(123.456);
    final Module module = ops.module("test.infinity", value);
    assertSame(value, module.getInput("arg"));
    assertFalse(Double.isInfinite(value.get()));
    module.run();
    assertTrue(Double.isInfinite(value.get()));
}
Also used : DoubleType(net.imglib2.type.numeric.real.DoubleType) Module(org.scijava.module.Module) Test(org.junit.Test)

Aggregations

Module (org.scijava.module.Module)12 Test (org.junit.Test)5 DoubleType (net.imglib2.type.numeric.real.DoubleType)4 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TableData (omero.gateway.model.TableData)1 CommandInfo (org.scijava.command.CommandInfo)1 ModuleRunner (org.scijava.module.ModuleRunner)1 PreprocessorPlugin (org.scijava.module.process.PreprocessorPlugin)1