Skip to content

Commit ebc55de

Browse files
authored
Merge pull request #91 from scijava/imagej/imagej-ops2/add-convert-type-tests
Add tests for ConvertTypes
2 parents dd16e9a + d906a39 commit ebc55de

11 files changed

Lines changed: 4690 additions & 66 deletions

File tree

‎imagej/imagej-ops2/bin/generate.groovy‎

100644100755
File mode changed.

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/convert/ConvertTypes.java‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
7070
/**
7171
* @input input
7272
* @container output
73-
* @implNote op names='convert.bit'
73+
* @implNote op names='convert.bit', priority='10.'
7474
*/
7575
public final Computers.Arity1<T, BitType> integerToBit = (input, output) -> output.set(input.getIntegerLong() != 0);
7676

@@ -84,7 +84,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
8484
/**
8585
* @input input
8686
* @container output
87-
* @implNote op names='convert.uint2'
87+
* @implNote op names='convert.uint2', priority='10.'
8888
*/
8989
public final Computers.Arity1<T, Unsigned2BitType> integerToUint2 = (input, output) -> output.set(input.getIntegerLong());
9090

@@ -98,21 +98,21 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
9898
/**
9999
* @input input
100100
* @container output
101-
* @implNote op names='convert.uint4'
101+
* @implNote op names='convert.uint4', priority='10.'
102102
*/
103103
public final Computers.Arity1<T, Unsigned4BitType> integerToUint4 = (input, output) -> output.set(input.getIntegerLong());
104104

105105
/**
106106
* @input input
107107
* @container output
108-
* @implNote op names='convert.byte'
108+
* @implNote op names='convert.int8, convert.byte'
109109
*/
110110
public final Computers.Arity1<C, ByteType> complexToInt8 = (input, output) -> output.set((byte) input.getRealDouble());
111111

112112
/**
113113
* @input input
114114
* @container output
115-
* @implNote op names='convert.byte'
115+
* @implNote op names='convert.int8, convert.byte', priority='10.'
116116
*/
117117
public final Computers.Arity1<T, ByteType> integerToInt8 = (input, output) -> output.set((byte) input.getIntegerLong());
118118

@@ -126,7 +126,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
126126
/**
127127
* @input input
128128
* @container output
129-
* @implNote op names='convert.uint8'
129+
* @implNote op names='convert.uint8', priority='10.'
130130
*/
131131
public final Computers.Arity1<T, UnsignedByteType> integerToUint8 = (input, output) -> output.set(input.getInteger());
132132

@@ -140,7 +140,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
140140
/**
141141
* @input input
142142
* @container output
143-
* @implNote op names='convert.uint12'
143+
* @implNote op names='convert.uint12', priority='10.'
144144
*/
145145
public final Computers.Arity1<T, Unsigned12BitType> integerToUint12 = (input, output) -> output.set(input.getIntegerLong());
146146

@@ -154,7 +154,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
154154
/**
155155
* @input input
156156
* @container output
157-
* @implNote op names='convert.int16'
157+
* @implNote op names='convert.int16', priority='10.'
158158
*/
159159
public final Computers.Arity1<T, ShortType> integerToInt16 = (input, output) -> output.set((short) input.getIntegerLong());
160160

@@ -168,7 +168,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
168168
/**
169169
* @input input
170170
* @container output
171-
* @implNote op names='convert.uint16'
171+
* @implNote op names='convert.uint16', priority='10.'
172172
*/
173173
public final Computers.Arity1<T, UnsignedShortType> integerToUint16 = (input, output) -> output.set(input.getInteger());
174174

@@ -182,7 +182,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
182182
/**
183183
* @input input
184184
* @container output
185-
* @implNote op names='convert.int32'
185+
* @implNote op names='convert.int32', priority='10.'
186186
*/
187187
public final Computers.Arity1<T, IntType> integerToInt32 = (input, output) -> output.set(input.getInteger());
188188

@@ -196,7 +196,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
196196
/**
197197
* @input input
198198
* @container output
199-
* @implNote op names='convert.uint32'
199+
* @implNote op names='convert.uint32', priority='10.'
200200
*/
201201
public final Computers.Arity1<T, UnsignedIntType> integerToUint32 = (input, output) -> output.set(input.getIntegerLong());
202202

@@ -210,7 +210,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
210210
/**
211211
* @input input
212212
* @container output
213-
* @implNote op names='convert.int64'
213+
* @implNote op names='convert.int64', priority='10.'
214214
*/
215215
public final Computers.Arity1<T, LongType> integerToInt64 = (input, output) -> output.set(input.getIntegerLong());
216216

@@ -229,6 +229,14 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
229229
}
230230
};
231231

232+
/**
233+
* @input input
234+
* @container output
235+
* @implNote op names='convert.uint64', priority='10.'
236+
*/
237+
public final Computers.Arity1<T, UnsignedLongType> integerToUint64 = (input, output) -> output.set(input.getIntegerLong());
238+
239+
232240
/**
233241
* @input input
234242
* @container output
@@ -247,7 +255,7 @@ public final class ConvertTypes<C extends ComplexType<C>, T extends IntegerType<
247255
/**
248256
* @input input
249257
* @container output
250-
* @implNote op names='convert.uint128'
258+
* @implNote op names='convert.uint128', priority='10.'
251259
*/
252260
public final Computers.Arity1<T, Unsigned128BitType> integerToUint128 = (input, output) -> output.set(input.getBigInteger());
253261

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/convert/Types.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,15 @@ private static byte[] validBytes(final byte[] value) {
183183

184184
public static float float32(final double value) { return (float) value; }
185185

186-
public static float float32(final BigInteger value) { return value.and(mask128).longValue(); }
186+
public static float float32(final BigInteger value) { return value.and(mask128).floatValue(); }
187187

188188
public static float float32(final boolean value) { return value ? 1 : 0; }
189189

190190
public static double float64(final long value) { return value; }
191191

192192
public static double float64(final double value) { return value; }
193193

194-
public static double float64(final BigInteger value) { return value.and(mask128).longValue(); }
194+
public static double float64(final BigInteger value) { return value.and(mask128).doubleValue(); }
195195

196196
public static double float64(final boolean value) { return value ? 1 : 0; }
197197

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/create/CreateTypes.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ public class CreateTypes {
141141
public final Producer<ComplexFloatType> cfloat32TypeSource = () -> new ComplexFloatType();
142142

143143
/**
144+
* NB higher priority to match {@code Producer<RealType>} and {@code Producer<NativeType>}
145+
*
144146
* @output output
145-
* @implNote op names='create, create.float64'
147+
* @implNote op names='create, create.float64', priority='100.'
146148
*/
147149
public final Producer<DoubleType> float64TypeSource = () -> new DoubleType();
148150

‎imagej/imagej-ops2/src/main/java/net/imagej/ops2/create/Creators.java‎

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
package net.imagej.ops2.create;
3030

31+
import java.lang.reflect.InvocationTargetException;
3132
import java.util.Arrays;
3233
import java.util.function.BiFunction;
3334
import java.util.function.Function;
@@ -214,14 +215,6 @@ public class Creators<N extends NativeType<N>, L, I extends IntegerType<I>, T ex
214215
.factory() //
215216
.create(input.dimensionsAsLongArray());
216217

217-
/* IntegerType */
218-
219-
/**
220-
* @output integerType
221-
* @implNote op names='create, create.integerType', priority='0.'
222-
*/
223-
public final Producer<LongType> integerTypeSource = () -> new LongType();
224-
225218
/* Type */
226219

227220
/**
@@ -231,12 +224,6 @@ public class Creators<N extends NativeType<N>, L, I extends IntegerType<I>, T ex
231224
*/
232225
public final Function<T, T> typeFromSampleType = (sample) -> sample.createVariable();
233226

234-
/**
235-
* @output booleanType
236-
* @implNote op names='create, create.type', priority='-100.'
237-
*/
238-
public final Producer<BitType> booleanTypeSource = () -> new BitType();
239-
240227
/* ImgLabeling */
241228

242229
/**
@@ -589,8 +576,8 @@ public class Creators<N extends NativeType<N>, L, I extends IntegerType<I>, T ex
589576
* @output labelingMapping
590577
* @implNote op names='create, create.labelingMapping'
591578
*/
592-
public final Producer<LabelingMapping<L>> labelingMappingSource = () -> new LabelingMapping<>(
593-
integerTypeSource.create());
579+
public final Producer<LabelingMapping<L>> labelingMappingSource = //
580+
() -> new LabelingMapping<>(new LongType());
594581

595582
public final Function<Long, IntegerType> integerTypeFromLong = (maxValue) -> {
596583
if (maxValue <= 0L)
@@ -629,30 +616,12 @@ public class Creators<N extends NativeType<N>, L, I extends IntegerType<I>, T ex
629616
*/
630617
public final Function<Class<L>, L> object = (clazz) -> {
631618
try {
632-
return clazz.newInstance();
633-
} catch (final InstantiationException exc) {
634-
throw new IllegalArgumentException(exc);
635-
} catch (final IllegalAccessException exc) {
636-
throw new IllegalArgumentException(exc);
619+
return clazz.getDeclaredConstructor().newInstance();
620+
} catch (final InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
621+
throw new IllegalArgumentException(e);
637622
}
638623
};
639624

640-
/* NativeType */
641-
642-
/**
643-
* @output nativeType
644-
* @implNote op names='create, create.nativeType', priority='100.'
645-
*/
646-
public final Producer<DoubleType> defaultNativeType = () -> new DoubleType();
647-
648-
// TODO is this a safe cast?
649-
/**
650-
* @input type
651-
* @output nativeType
652-
* @implNote op names='create, create.nativeType'
653-
*/
654-
public final Function<Class<N>, N> nativeTypeFromClass = (clazz) -> (N) object.apply((Class<L>) clazz);
655-
656625
/**
657626
* @output vector3d
658627
* @implNote op names='create, create.vector'

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/OpRegressionTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class OpRegressionTest extends AbstractOpTest {
3939

4040
@Test
4141
public void opDiscoveryRegressionIT() {
42-
long expected = 1466;
42+
long expected = 1463;
4343
long actual = ops.infos().size();
4444
assertEquals(expected, actual);
4545
}

0 commit comments

Comments
 (0)