Skip to content

Commit

Permalink
feat: introduce FP_TOLERANCE and used where required
Browse files Browse the repository at this point in the history
  • Loading branch information
furqaankhan committed Nov 21, 2023
1 parent b99edbc commit 2999f5f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void testSummaryStatsWithAllNoData() throws FactoryException {
emptyRaster = MapAlgebra.addBandFromArray(emptyRaster, values, 1, 0d);
double[] actual = RasterBandAccessors.getSummaryStats(emptyRaster);
double[] expected = {0.0, 0.0, Double.NaN, Double.NaN, Double.NaN, Double.NaN};
assertArrayEquals(expected, actual, 1e-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);
}

@Test
Expand All @@ -207,30 +207,30 @@ public void testSummaryStatsWithEmptyRaster() throws FactoryException {
emptyRaster = MapAlgebra.addBandFromArray(emptyRaster, values2, 2, 0d);
double[] actual = RasterBandAccessors.getSummaryStats(emptyRaster, 1, false);
double[] expected = {25.0, 204.0, 8.1600, 9.2765, 0.0, 25.0};
assertArrayEquals(expected, actual, 1e-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getSummaryStats(emptyRaster, 2);
expected = new double[]{16.0, 642.0, 40.125, 6.9988838395847095, 28.0, 50.0};
assertArrayEquals(expected, actual, 1e-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getSummaryStats(emptyRaster);
expected = new double[] {14.0, 204.0, 14.5714, 7.7617, 1.0, 25.0};
assertArrayEquals(expected, actual, 1e-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);
}

@Test
public void testSummaryStatsWithRaster() throws IOException {
GridCoverage2D raster = rasterFromGeoTiff(resourceFolder + "raster/raster_with_no_data/test5.tiff");
double[] actual = RasterBandAccessors.getSummaryStats(raster, 1, false);
double[] expected = {1036800.0, 2.06233487E8, 198.9134, 95.0905, 0.0, 255.0};
assertArrayEquals(expected, actual, 1e-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getSummaryStats(raster, 1);
expected = new double[]{928192.0, 2.06233487E8, 222.1883, 70.2055, 1.0, 255.0};
assertArrayEquals(expected, actual, 1e-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getSummaryStats(raster);
assertArrayEquals(expected, actual, 1E-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class RasterTestBase {

protected static final String resourceFolder = System.getProperty("user.dir") + "/../spark/common/src/test/resources/";

protected static final double FP_TOLERANCE = 1E-4;

GridCoverage2D oneBandRaster;
GridCoverage2D multiBandRaster;
byte[] geoTiff;
Expand Down

0 comments on commit 2999f5f

Please sign in to comment.