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();
}
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.
}
}
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()));
}
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());
}
}
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()));
}
Aggregations