|
| 1 | +package net.imagej.testutil; |
| 2 | + |
| 3 | +import net.imglib2.Cursor; |
| 4 | +import net.imglib2.img.array.ArrayImg; |
| 5 | +import net.imglib2.type.NativeType; |
| 6 | +import net.imglib2.type.logic.BitType; |
| 7 | +import net.imglib2.type.numeric.integer.*; |
| 8 | +import net.imglib2.type.numeric.real.DoubleType; |
| 9 | +import net.imglib2.type.numeric.real.FloatType; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | + |
| 12 | +import static org.junit.jupiter.api.Assertions.*; |
| 13 | + |
| 14 | +public class TestImgGenerationTest { |
| 15 | + |
| 16 | + @Test |
| 17 | + public void verifyImages() { |
| 18 | + ensureNotEmpty(TestImgGeneration.byteArray(true, 10, 10), new ByteType()); |
| 19 | + ensureNotEmpty(TestImgGeneration.unsignedByteArray(true, 10, 10), new UnsignedByteType()); |
| 20 | + ensureNotEmpty(TestImgGeneration.intArray(true, 10, 10), new IntType()); |
| 21 | + ensureNotEmpty(TestImgGeneration.unsignedIntArray(true, 10, 10), new UnsignedIntType()); |
| 22 | + ensureNotEmpty(TestImgGeneration.floatArray(true, 10, 10), new FloatType()); |
| 23 | + ensureNotEmpty(TestImgGeneration.doubleArray(true, 10, 10), new DoubleType()); |
| 24 | + ensureNotEmpty(TestImgGeneration.bitArray(true, 10, 10), new BitType()); |
| 25 | + ensureNotEmpty(TestImgGeneration.longArray(true, 10, 10), new LongType()); |
| 26 | + ensureNotEmpty(TestImgGeneration.unsignedLongArray(true, 10, 10), new UnsignedLongType()); |
| 27 | + ensureNotEmpty(TestImgGeneration.shortArray(true, 10, 10), new ShortType()); |
| 28 | + ensureNotEmpty(TestImgGeneration.unsignedShortArray(true, 10, 10), new UnsignedShortType()); |
| 29 | + ensureNotEmpty(TestImgGeneration.unsigned2BitArray(true, 10, 10), new Unsigned2BitType()); |
| 30 | + ensureNotEmpty(TestImgGeneration.unsigned4BitArray(true, 10, 10), new Unsigned4BitType()); |
| 31 | + ensureNotEmpty(TestImgGeneration.unsigned12BitArray(true, 10, 10), new Unsigned12BitType()); |
| 32 | + ensureNotEmpty(TestImgGeneration.unsigned128BitArray(true, 10, 10), new Unsigned128BitType()); |
| 33 | + } |
| 34 | + |
| 35 | + private void ensureNotEmpty(ArrayImg img, NativeType nt) { |
| 36 | + Cursor<?> cursor = img.cursor(); |
| 37 | + boolean foundNonZero = false; |
| 38 | + while (cursor.hasNext()) { |
| 39 | + foundNonZero = (!cursor.next().equals(nt)) || foundNonZero; |
| 40 | + } |
| 41 | + assertTrue(foundNonZero, "Randomly generated " + nt.getClass() + " array contains all 0's"); |
| 42 | + } |
| 43 | +} |
0 commit comments