Skip to content

Commit fb8feb3

Browse files
committed
Test ImgLib2 descriptor extensibility
1 parent 58b9b02 commit fb8feb3

File tree

3 files changed

+91
-30
lines changed

3 files changed

+91
-30
lines changed

scijava-ops-image/src/main/java/org/scijava/ops/image/describe/ImgLib2Descriptors.java

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,71 @@
1212

1313
import java.util.function.Function;
1414

15-
public class ImgLib2Descriptors< //
16-
A, //
17-
C extends ComplexType<C>, //
18-
I extends IntegerType<I>, //
19-
T extends RealType<T> //
20-
> {
15+
/**
16+
* {@code engine.describe} Ops pertaining to ImgLib2 types.
17+
* <p>
18+
* Note that each input is a {@code Nil<T>}, where {@code T} is a type variable
19+
* bounded by the type we actually want to describe. This provides
20+
* extensibility, as it allows e.g. {@link #raiDesc(Nil)} to be used for e.g.
21+
* {@link net.imglib2.img.array.ArrayImg}s
22+
* </p>
23+
*
24+
* @author Gabriel Selzer
25+
*/
26+
public class ImgLib2Descriptors {
2127

2228
/**
23-
* @input the type to describe
24-
* @output the description
29+
* @param in the type to describe
30+
* @return the description
2531
* @implNote op name="engine.describe"
2632
*/
27-
public final Function<Nil<IterableInterval<A>>, String> iiDesc = //
28-
in -> "image";
33+
public static <A, T extends IterableInterval<A>> String iiDesc( //
34+
Nil<T> in //
35+
) {
36+
return "image";
37+
}
2938

3039
/**
31-
* @input the type to describe
32-
* @output the description
33-
* @implNote op name="engine.describe", priority="100."
40+
* @param in the type to describe
41+
* @return the description
42+
* @implNote op name="engine.describe", priority='100.'
3443
*/
35-
public final Function<Nil<RandomAccessibleInterval<A>>, String> raiDesc = //
36-
in -> "image";
44+
public static <A, T extends RandomAccessibleInterval<A>> String raiDesc( //
45+
Nil<T> in //
46+
) {
47+
return "image";
48+
}
3749

3850
/**
39-
* @input the type to describe
40-
* @output the description
41-
* @implNote op name="engine.describe", priority="1000."
51+
* @param in the type to describe
52+
* @return the description
53+
* @implNote op name="engine.describe", priority='10000.'
4254
*/
43-
public final Function<Nil<ImgLabeling<A, I>>, String> imgLabelDesc = //
44-
in -> "labels";
55+
public static <A, I extends IntegerType<I>, T extends ImgLabeling<A, I>>
56+
String labelDesc(Nil<T> in)
57+
{
58+
return "labels";
59+
}
4560

4661
/**
47-
* @input the type to describe
48-
* @output the description
62+
* @param in the type to describe
63+
* @return the description
4964
* @implNote op name="engine.describe", priority='100.'
5065
*/
51-
public final Function<Nil<T>, String> realTypeDesc = //
52-
in -> "number";
66+
public static <T extends RealType<T>> String realTypeDesc( //
67+
Nil<T> in //
68+
) {
69+
return "number";
70+
}
5371

5472
/**
55-
* @input the type to describe
56-
* @output the description
73+
* @param in the type to describe
74+
* @return the description
5775
* @implNote op name="engine.describe"
5876
*/
59-
public final Function<Nil<C>, String> complexTypeDesc = //
60-
in -> "complex number";
77+
public static <T extends ComplexType<T>> String complexTypeDesc( //
78+
Nil<T> in //
79+
) {
80+
return "complex number";
81+
}
6182
}

scijava-ops-image/src/test/java/org/scijava/ops/image/OpRegressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class OpRegressionTest {
4242

4343
@Test
4444
public void opDiscoveryRegressionIT() {
45-
long expected = 1922;
45+
long expected = 1923;
4646
long actual = ops.infos().size();
4747
assertEquals(expected, actual);
4848
}

scijava-ops-image/src/test/java/org/scijava/ops/image/describe/DescriptorsTest.java renamed to scijava-ops-image/src/test/java/org/scijava/ops/image/describe/ImgLib2DescriptorsTest.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@
33

44
import net.imglib2.IterableInterval;
55
import net.imglib2.RandomAccessibleInterval;
6+
import net.imglib2.img.array.ArrayImg;
7+
import net.imglib2.img.basictypeaccess.DataAccess;
68
import net.imglib2.loops.LoopBuilder;
79
import net.imglib2.roi.labeling.ImgLabeling;
10+
import net.imglib2.type.NativeType;
811
import net.imglib2.type.numeric.ComplexType;
912
import net.imglib2.type.numeric.IntegerType;
1013
import net.imglib2.type.numeric.RealType;
1114
import org.junit.jupiter.api.Assertions;
1215
import org.junit.jupiter.api.Test;
1316
import org.scijava.ops.image.AbstractOpTest;
17+
import org.scijava.types.Types;
1418

15-
public class DescriptorsTest extends AbstractOpTest {
19+
import java.lang.reflect.ParameterizedType;
20+
21+
/**
22+
* Tests {@link ImgLib2Descriptors}.
23+
*
24+
* @author Gabriel Selzer
25+
*/
26+
public class ImgLib2DescriptorsTest extends AbstractOpTest {
1627

1728
/**
1829
* @implNote op name=example.describeRealType, type=Inplace
@@ -95,4 +106,33 @@ public void testImgLabelingDescription() {
95106
Assertions.assertEquals(expected, actual);
96107
}
97108

109+
/**
110+
* @implNote op name=example.describeArrayImg, type=Inplace
111+
*/
112+
public static <T extends NativeType<T>, A extends DataAccess> void
113+
randomAccessibleInterval(ArrayImg<T, A> in)
114+
{}
115+
116+
/**
117+
* This test ensures description extensibility for ImgLib2 image types
118+
*/
119+
@Test
120+
public void testArrayImgDescription() {
121+
// First, ensure there is no descriptor FOR ArrayImgs
122+
for (var info : ops.infos("engine.describe")) {
123+
var in = info.inputTypes().get(0);
124+
Assertions.assertInstanceOf(ParameterizedType.class, in);
125+
var descriptorType = ((ParameterizedType) in).getActualTypeArguments()[0];
126+
Assertions.assertFalse( //
127+
Types.isAssignable(descriptorType, ArrayImg.class) //
128+
);
129+
}
130+
131+
// Then, ensure that we get a description anyways
132+
var expected = "example.describeArrayImg:\n" +
133+
"\t- (@MUTABLE image) -> None";
134+
var actual = ops.help("example.describeArrayImg");
135+
Assertions.assertEquals(expected, actual);
136+
}
137+
98138
}

0 commit comments

Comments
 (0)