|
14 | 14 | import org.junit.Assert; |
15 | 15 | import org.junit.Test; |
16 | 16 | import org.scijava.function.Computers; |
| 17 | +import org.scijava.function.Inplaces; |
17 | 18 | import org.scijava.ops.AbstractTestEnvironment; |
| 19 | +import org.scijava.ops.OpDependency; |
18 | 20 | import org.scijava.ops.OpField; |
19 | 21 | import org.scijava.ops.OpInfo; |
20 | 22 | import org.scijava.ops.OpMethod; |
@@ -77,6 +79,20 @@ public static List<Long> OpMethodIR(List<String> foo, List<String> bar) { |
77 | 79 | .toList()); |
78 | 80 | } |
79 | 81 |
|
| 82 | + /** |
| 83 | + * Tests javadoc scraping with input (I) ONLY |
| 84 | + * |
| 85 | + * @input foo the first input |
| 86 | + * @input bar the second input |
| 87 | + */ |
| 88 | + @OpMethod(names = "test.javadoc.methodI", type = BiFunction.class) |
| 89 | + public static List<Long> OpMethodI(List<String> foo, List<String> bar) { |
| 90 | + BiFunction<String, String, Long> func = (s1, s2) -> Long.parseLong(s1) + |
| 91 | + Long.parseLong(s2); |
| 92 | + return Streams.zip(foo.stream(), bar.stream(), func).collect(Collectors |
| 93 | + .toList()); |
| 94 | + } |
| 95 | + |
80 | 96 | @Test |
81 | 97 | public void testJavadocMethodPR() { |
82 | 98 | Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodPR").iterator(); |
@@ -110,6 +126,101 @@ public void testJavadocMethodIR() { |
110 | 126 | isSuitableGenericOpMethodInfo(info); |
111 | 127 | } |
112 | 128 |
|
| 129 | + @Test |
| 130 | + public void testJavadocMethodI() { |
| 131 | + Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodI").iterator(); |
| 132 | + |
| 133 | + OpInfo info = infos.next(); |
| 134 | + if (infos.hasNext()) { |
| 135 | + Assert.fail("Multiple OpInfos with name \"test.javadoc.method\""); |
| 136 | + } |
| 137 | + isSuitableGenericOpMethodInfo(info); |
| 138 | + } |
| 139 | + |
| 140 | + /** |
| 141 | + * Tests javadoc scraping of mutable taglet |
| 142 | + * |
| 143 | + * @mutable foo the i/o argument |
| 144 | + */ |
| 145 | + @OpMethod(names = "test.javadoc.methodInplaceI", type = Inplaces.Arity1.class) |
| 146 | + public static void OpMethodInplaceI(List<String> foo) { |
| 147 | + for (int i = 0; i < foo.size(); i++) { |
| 148 | + foo.set(i, foo.get(i) + " foo"); |
| 149 | + } |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Tests javadoc scraping of mutable taglet |
| 154 | + * |
| 155 | + * @dependency inplace the Op being wrapped |
| 156 | + * @mutable foo the i/o argument |
| 157 | + */ |
| 158 | + @OpMethod(names = "test.javadoc.methodDependency", type = Inplaces.Arity1.class) |
| 159 | + public static void OpMethodInplaceI(@OpDependency( |
| 160 | + name = "test.javadoc.methodInplaceI") Inplaces.Arity1<List<String>> inplace, |
| 161 | + List<String> foo) |
| 162 | + { |
| 163 | + inplace.mutate(foo); |
| 164 | + } |
| 165 | + |
| 166 | + @Test |
| 167 | + public void testJavadocMethodInplaceI() { |
| 168 | + Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodInplaceI").iterator(); |
| 169 | + |
| 170 | + OpInfo info = infos.next(); |
| 171 | + if (infos.hasNext()) { |
| 172 | + Assert.fail("Multiple OpInfos with name \"test.javadoc.method\""); |
| 173 | + } |
| 174 | + |
| 175 | + // assert input names |
| 176 | + String[] inputNames = info.inputs().stream().map(m -> m.getKey()).toArray( |
| 177 | + String[]::new); |
| 178 | + Assert.assertArrayEquals(inputNames, new String[] { "foo" }); |
| 179 | + |
| 180 | + // assert input descriptions |
| 181 | + String[] inputDescriptions = info.inputs().stream().map(m -> m |
| 182 | + .getDescription()).toArray(String[]::new); |
| 183 | + Assert.assertArrayEquals(inputDescriptions, new String[] { |
| 184 | + "the i/o argument"}); |
| 185 | + |
| 186 | + // assert output name |
| 187 | + String outputName = info.output().getKey(); |
| 188 | + Assert.assertEquals("foo", outputName); |
| 189 | + |
| 190 | + // assert output description |
| 191 | + String outputDescription = info.output().getDescription(); |
| 192 | + Assert.assertEquals("the i/o argument", outputDescription); |
| 193 | + } |
| 194 | + |
| 195 | + @Test |
| 196 | + public void testJavadocMethodInplaceWithDepedency() { |
| 197 | + Iterator<OpInfo> infos = ops.env().infos("test.javadoc.methodDependency").iterator(); |
| 198 | + |
| 199 | + OpInfo info = infos.next(); |
| 200 | + if (infos.hasNext()) { |
| 201 | + Assert.fail("Multiple OpInfos with name \"test.javadoc.methodDependency\""); |
| 202 | + } |
| 203 | + |
| 204 | + // assert input names |
| 205 | + String[] inputNames = info.inputs().stream().map(m -> m.getKey()).toArray( |
| 206 | + String[]::new); |
| 207 | + Assert.assertArrayEquals(inputNames, new String[] { "foo" }); |
| 208 | + |
| 209 | + // assert input descriptions |
| 210 | + String[] inputDescriptions = info.inputs().stream().map(m -> m |
| 211 | + .getDescription()).toArray(String[]::new); |
| 212 | + Assert.assertArrayEquals(inputDescriptions, new String[] { |
| 213 | + "the i/o argument"}); |
| 214 | + |
| 215 | + // assert output name |
| 216 | + String outputName = info.output().getKey(); |
| 217 | + Assert.assertEquals("foo", outputName); |
| 218 | + |
| 219 | + // assert output description |
| 220 | + String outputDescription = info.output().getDescription(); |
| 221 | + Assert.assertEquals("the i/o argument", outputDescription); |
| 222 | + } |
| 223 | + |
113 | 224 | /** |
114 | 225 | * Asserts that the {@link OpInfo} has as inputs: |
115 | 226 | * <ul> |
|
0 commit comments