Skip to content

Commit 6d351ef

Browse files
committed
Ensure TestImgs are not empty
1 parent ff3902c commit 6d351ef

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

imagej/imagej-testutil/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,16 @@
115115
<groupId>net.imglib2</groupId>
116116
<artifactId>imglib2</artifactId>
117117
</dependency>
118+
<!-- Test scope dependencies -->
119+
<dependency>
120+
<groupId>org.junit.jupiter</groupId>
121+
<artifactId>junit-jupiter-api</artifactId>
122+
<scope>test</scope>
123+
</dependency>
124+
<dependency>
125+
<groupId>org.junit.jupiter</groupId>
126+
<artifactId>junit-jupiter-engine</artifactId>
127+
<scope>test</scope>
128+
</dependency>
118129
</dependencies>
119130
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)