Skip to content

Commit eaa8d43

Browse files
authored
Merge pull request #62 from scijava/update-abstract-tests
Update abstract tests
2 parents a245ba7 + 53cb07e commit eaa8d43

13 files changed

Lines changed: 53 additions & 35 deletions

File tree

imagej/imagej-ops2/src/test/java/net/imagej/ops2/features/AbstractFeatureTest.java renamed to imagej/imagej-ops2/src/test/java/net/imagej/ops2/AbstractFeatureTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* #L%
2828
*/
2929

30-
package net.imagej.ops2.features;
30+
package net.imagej.ops2;
3131

3232
import java.io.IOException;
3333
import java.net.URISyntaxException;
@@ -41,7 +41,6 @@
4141

4242
import net.imagej.mesh.Mesh;
4343
import net.imagej.mesh.naive.NaiveDoubleMesh;
44-
import net.imagej.ops2.AbstractOpTest;
4544
import net.imglib2.Cursor;
4645
import net.imglib2.IterableInterval;
4746
import net.imglib2.RandomAccess;
@@ -251,13 +250,13 @@ public Img<UnsignedByteType> getEllipsedBitImage(final long[] dim,
251250
}
252251

253252
protected static Img<FloatType> getTestImage2D() {
254-
return openFloatImg(AbstractFeatureTest.class, "2d_geometric_features_testlabel.tif");
253+
return openRelativeFloatImg(AbstractFeatureTest.class, "features/2d_geometric_features_testlabel.tif");
255254
}
256255

257256
protected static Polygon2D getPolygon() {
258257
final List<RealPoint> vertices = new ArrayList<>();
259258
try {
260-
Files.lines(Paths.get(AbstractFeatureTest.class.getResource("2d_geometric_features_polygon.txt").toURI()))
259+
Files.lines(Paths.get(AbstractFeatureTest.class.getResource("features/2d_geometric_features_polygon.txt").toURI()))
261260
.forEach(l -> {
262261
String[] coord = l.split(" ");
263262
RealPoint v = new RealPoint(new double[]{ Double.parseDouble(coord[0]),
@@ -271,7 +270,7 @@ protected static Polygon2D getPolygon() {
271270
}
272271

273272
protected static Img<FloatType> getTestImage3D() {
274-
return openFloatImg(AbstractFeatureTest.class, "3d_geometric_features_testlabel.tif");
273+
return openRelativeFloatImg(AbstractFeatureTest.class, "features/3d_geometric_features_testlabel.tif");
275274
}
276275

277276
protected static Mesh getMesh() {
@@ -280,7 +279,7 @@ protected static Mesh getMesh() {
280279
final Map<Vector3D, Long> indexMap = new HashMap<>();
281280
final LongArray indices = new LongArray();
282281
try {
283-
Files.lines(Paths.get(AbstractFeatureTest.class.getResource("3d_geometric_features_mesh.txt").toURI()))
282+
Files.lines(Paths.get(AbstractFeatureTest.class.getResource("features/3d_geometric_features_mesh.txt").toURI()))
284283
.forEach(l -> {
285284
String[] coord = l.split(" ");
286285
final double x = Double.parseDouble(coord[0]);

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,35 +95,56 @@ private int pseudoRandom() {
9595
return seed = 3170425 * seed + 132102;
9696
}
9797

98-
99-
98+
/**
99+
* Open a sample image from a resource path relative to {@link AbstractOpTest}
100+
*/
100101
public Img<FloatType> openFloatImg(final String resourcePath) {
101-
return openFloatImg(getClass(), resourcePath);
102+
return openRelativeFloatImg(getClass(), resourcePath);
102103
}
103104

105+
/**
106+
* Open a sample image from a resource path relative to {@link AbstractOpTest}
107+
*/
104108
public Img<DoubleType> openDoubleImg(final String resourcePath) {
105-
return openDoubleImg(getClass(), resourcePath);
109+
return openRelativeDoubleImg(getClass(), resourcePath);
110+
}
111+
112+
/**
113+
* Open a sample image from a resource path relative to {@link AbstractOpTest}
114+
*/
115+
public Img<UnsignedByteType> openUnsignedByteImg(final String resourcePath)
116+
{
117+
return openRelativeUnsignedByteImg(getClass(), resourcePath);
106118
}
107119

108-
public static Img<FloatType> openFloatImg(final Class<?> c,
120+
/**
121+
* Open a sample image from a resource path relative to a specified base class
122+
*/
123+
public static Img<FloatType> openRelativeFloatImg(final Class<?> base,
109124
final String resourcePath)
110125
{
111-
final URL url = c.getResource(resourcePath);
126+
final URL url = base.getResource(resourcePath);
112127
return IO.openFloat(url.getPath()).getImg();
113128
}
114129

115-
public static Img<UnsignedByteType> openUnsignedByteType(final Class<?> c,
130+
/**
131+
* Open a sample image from a resource path relative to a specified base class
132+
*/
133+
public static Img<DoubleType> openRelativeDoubleImg(final Class<?> base,
116134
final String resourcePath)
117135
{
118-
final URL url = c.getResource(resourcePath);
119-
return IO.openUnsignedByte(url.getPath()).getImg();
136+
final URL url = base.getResource(resourcePath);
137+
return IO.openDouble(url.getPath()).getImg();
120138
}
121139

122-
public static Img<DoubleType> openDoubleImg(final Class<?> c,
140+
/**
141+
* Open a sample image from a resource path relative to a specified base class
142+
*/
143+
public static Img<UnsignedByteType> openRelativeUnsignedByteImg(final Class<?> base,
123144
final String resourcePath)
124145
{
125-
final URL url = c.getResource(resourcePath);
126-
return IO.openDouble(url.getPath()).getImg();
146+
final URL url = base.getResource(resourcePath);
147+
return IO.openUnsignedByte(url.getPath()).getImg();
127148
}
128149

129150
public static <T> RandomAccessible<T> deinterval(

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/features/haralick/HaralickFeatureTest.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static org.junit.jupiter.api.Assertions.assertEquals;
3232

3333
import net.imagej.ops2.AbstractOpTest;
34-
import net.imagej.ops2.features.AbstractFeatureTest;
3534
import net.imagej.ops2.image.cooccurrenceMatrix.MatrixOrientation2D;
3635
import net.imglib2.img.Img;
3736
import net.imglib2.type.numeric.integer.UnsignedByteType;
@@ -60,7 +59,7 @@ public class HaralickFeatureTest extends AbstractOpTest {
6059

6160
@BeforeEach
6261
public void loadImage() {
63-
img = openUnsignedByteType(AbstractFeatureTest.class, "haralick_test_img.tif");
62+
img = openRelativeUnsignedByteImg(AbstractOpTest.class, "features/haralick_test_img.tif");
6463
}
6564

6665
@Test

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/features/lbp2d/LBP2dFeatureTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import java.util.ArrayList;
3434

35-
import net.imagej.ops2.features.AbstractFeatureTest;
35+
import net.imagej.ops2.AbstractFeatureTest;
3636
import net.imglib2.type.numeric.integer.LongType;
3737

3838
import org.junit.jupiter.api.Test;

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/features/tamura2d/Tamura2dFeatureTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import static org.junit.jupiter.api.Assertions.assertEquals;
3333

34-
import net.imagej.ops2.features.AbstractFeatureTest;
34+
import net.imagej.ops2.AbstractFeatureTest;
3535
import net.imglib2.img.Img;
3636
import net.imglib2.img.array.ArrayImgs;
3737
import net.imglib2.type.numeric.integer.ByteType;

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/features/zernike/ZernikeFeatureTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import static org.junit.jupiter.api.Assertions.assertEquals;
3232

33-
import net.imagej.ops2.features.AbstractFeatureTest;
33+
import net.imagej.ops2.AbstractFeatureTest;
3434
import net.imglib2.type.numeric.real.DoubleType;
3535

3636
import org.junit.jupiter.api.Test;

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/filter/tubeness/TubenessTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class TubenessTest extends AbstractOpTest {
4848

4949
@Test
5050
public void testTubeness() {
51-
Img<UnsignedByteType> input = openUnsignedByteType(DefaultTubeness.class, "TubesInput.png");
51+
Img<UnsignedByteType> input = openRelativeUnsignedByteImg(DefaultTubeness.class, "TubesInput.png");
5252
Img<DoubleType> expected = openDoubleImg("tube.tif");
5353

5454
final double scale = 5;

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/geom/geom2d/PolygonFeatureTests.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
import java.util.List;
3434

35-
import net.imagej.ops2.features.AbstractFeatureTest;
35+
import net.imagej.ops2.AbstractFeatureTest;
3636
import net.imagej.ops2.geom.GeomUtils;
3737
import net.imglib2.RealLocalizable;
3838
import net.imglib2.RealPoint;

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/geom/geom3d/MeshFeatureTests.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
import net.imagej.mesh.Mesh;
3737
import net.imagej.mesh.Triangle;
38-
import net.imagej.ops2.features.AbstractFeatureTest;
38+
import net.imagej.ops2.AbstractFeatureTest;
3939
import net.imglib2.roi.labeling.LabelRegion;
4040
import net.imglib2.type.numeric.real.DoubleType;
4141

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/image/watershed/WatershedBinarySingleSigmaTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class WatershedBinarySingleSigmaTest extends AbstractOpTest {
5959
@Test
6060
public void test() {
6161
// load test image
62-
Img<FloatType> watershedTestImg = openFloatImg(WatershedTest.class, "watershed_test_image.png");
62+
Img<FloatType> watershedTestImg = openRelativeFloatImg(WatershedTest.class, "watershed_test_image.png");
6363

6464
// retrieve an ExecutorService TODO is there a better way to do this?
6565
ExecutorService es = threads.getExecutorService();

0 commit comments

Comments
 (0)