Skip to content

Commit d17d33e

Browse files
committed
Use assertImageEquals when possible
1 parent 65abb18 commit d17d33e

File tree

3 files changed

+9
-25
lines changed

3 files changed

+9
-25
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Jean-Yves Tinevez and Michael Zinsmaier.</license.copyrightOwners>
200200
<!-- NB: Deploy releases to the ImageJ Maven repository. -->
201201
<releaseProfiles>deploy-to-imagej</releaseProfiles>
202202

203+
<imglib2.version>5.6.0</imglib2.version>
203204
<imglib2-realtransform.version>2.0.0-beta-39</imglib2-realtransform.version>
204205
<jitk-tps.version>3.0.0</jitk-tps.version>
205206
<ojalgo.version>43.0</ojalgo.version>

src/test/java/net/imglib2/algorithm/convolution/kernel/SeparableKernelConvolutionTest.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.imglib2.algorithm.convolution.Convolution;
88
import net.imglib2.img.Img;
99
import net.imglib2.img.array.ArrayImgs;
10+
import net.imglib2.test.ImgLib2Assert;
1011
import net.imglib2.type.numeric.ARGBType;
1112
import net.imglib2.type.numeric.NumericType;
1213
import net.imglib2.type.numeric.integer.UnsignedByteType;
@@ -21,8 +22,6 @@
2122
import java.util.stream.IntStream;
2223
import java.util.stream.Stream;
2324

24-
import static org.junit.Assert.assertArrayEquals;
25-
import static org.junit.Assert.assertEquals;
2625
import static org.junit.Assert.assertTrue;
2726

2827
/**
@@ -76,7 +75,7 @@ private void testSeparableConvolution( Kernel1D[] kernels1d )
7675
RandomAccessibleInterval< DoubleType > expected = getKernel( kernels1d );
7776
RandomAccessibleInterval< DoubleType > result = createImg( expected );
7877
SeparableKernelConvolution.convolve( kernels1d, dirac, result );
79-
assertImagesEqual( expected, result, 0.0 );
78+
ImgLib2Assert.assertImageEquals( expected, result );
8079
}
8180

8281
private RandomAccessible< DoubleType > getDirac( int n )
@@ -119,24 +118,16 @@ private static RandomAccessibleInterval< DoubleType > createImg( Interval interv
119118
return Views.translate( image, Intervals.minAsLongArray( interval ) );
120119
}
121120

122-
private static void assertImagesEqual( RandomAccessibleInterval< DoubleType > expected, RandomAccessibleInterval< DoubleType > actual, double delta )
123-
{
124-
assertTrue( Intervals.equals( expected, actual ) );
125-
Views.interval( Views.pair( expected, actual ), expected ).forEach( p -> assertEquals( p.getA().getRealDouble(), p.getB().getRealDouble(), delta ) );
126-
}
127-
128121
@Test
129122
public void testPrecisionOfTemporaryImages() {
130123
// NB: This test assures that for convolution on UnsignedByteType,
131124
// the pixel type to store intermediate results can store 0.1, hence
132125
// is FloatType or DoubleType.
133-
final byte[] inputPixels = { 1 };
134-
final byte[] outputPixels = new byte[ 1 ];
135126
final Kernel1D[] kernels = { Kernel1D.symmetric( 0.1 ), Kernel1D.symmetric( 10 ) };
136-
Img< UnsignedByteType > input = ArrayImgs.unsignedBytes( inputPixels, 1, 1 );
137-
Img< UnsignedByteType > output = ArrayImgs.unsignedBytes( outputPixels, 1, 1 );
127+
Img< UnsignedByteType > input = ArrayImgs.unsignedBytes( new byte[] { 1 }, 1, 1 );
128+
Img< UnsignedByteType > output = ArrayImgs.unsignedBytes( new byte[] { 0 }, 1, 1 );
138129
SeparableKernelConvolution.convolution( kernels ).process( input, output );
139-
assertArrayEquals( inputPixels, outputPixels );
130+
ImgLib2Assert.assertImageEquals( input, output );
140131
}
141132

142133
@Test

src/test/java/net/imglib2/algorithm/gauss3/SeparableSymmetricConvolutionTest.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.imglib2.img.Img;
88
import net.imglib2.img.array.ArrayImgFactory;
99
import net.imglib2.img.array.ArrayImgs;
10+
import net.imglib2.test.ImgLib2Assert;
1011
import net.imglib2.type.numeric.real.DoubleType;
1112
import net.imglib2.util.Intervals;
1213
import net.imglib2.view.Views;
@@ -16,9 +17,6 @@
1617
import java.util.concurrent.Executors;
1718
import java.util.stream.IntStream;
1819

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.assertTrue;
21-
2220
/**
2321
* @author Matthias Arzt
2422
*/
@@ -40,7 +38,7 @@ public void testConvolve() throws IncompatibleTypeException
4038
{
4139
RandomAccessibleInterval< DoubleType > target = createImg( expected );
4240
SeparableSymmetricConvolution.convolve( halfKernels, getDirac( halfKernels.length ), target, service );
43-
assertImagesEqual( expected, target, 0.0 );
41+
ImgLib2Assert.assertImageEquals( expected, target );
4442
}
4543

4644
@Test
@@ -50,7 +48,7 @@ public void testConvolve2()
5048
ConvolverFactory< DoubleType, DoubleType > factory = FloatConvolverRealType.factory();
5149
SeparableSymmetricConvolution.convolve( halfKernels, getDirac( halfKernels.length ), target,
5250
factory, factory, factory, factory, new ArrayImgFactory<>(), new DoubleType(), service );
53-
assertImagesEqual( expected, target, 0.0 );
51+
ImgLib2Assert.assertImageEquals( expected, target );
5452
}
5553

5654
@Test
@@ -76,10 +74,4 @@ public static RandomAccessibleInterval< DoubleType > createImg( Interval interva
7674
Img< DoubleType > image = ArrayImgs.doubles( Intervals.dimensionsAsLongArray( interval ) );
7775
return Views.translate( image, Intervals.minAsLongArray( interval ) );
7876
}
79-
80-
public static void assertImagesEqual( RandomAccessibleInterval< DoubleType > expected, RandomAccessibleInterval< DoubleType > actual, double delta )
81-
{
82-
assertTrue( Intervals.equals( expected, actual ) );
83-
Views.interval( Views.pair( expected, actual ), expected ).forEach( p -> assertEquals( p.getA().getRealDouble(), p.getB().getRealDouble(), delta ) );
84-
}
8577
}

0 commit comments

Comments
 (0)