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 37bd597 commit ca3dd5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public void testZonalStats() throws FactoryException, ParseException, IOExceptio

actual = RasterBandAccessors.getZonalStats(raster, geom, 2, "mean", false);
expected = 220.6062;
assertEquals(expected, actual, 1E-4);
assertEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getZonalStats(raster, geom, 1, "count");
expected = 184792.0;
assertEquals(expected, actual, 0.1d);

actual = RasterBandAccessors.getZonalStats(raster, geom, 3, "variance", false);
expected = 13554.5057;
assertEquals(expected, actual, 1E-4);
assertEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getZonalStats(raster, geom, "max");
expected = 255.0;
Expand All @@ -113,7 +113,7 @@ public void testZonalStats() throws FactoryException, ParseException, IOExceptio

actual = RasterBandAccessors.getZonalStats(raster, geom, 1, "sd", false);
expected = 92.1327;
assertEquals(expected, actual, 1E-4);
assertEquals(expected, actual, FP_TOLERANCE);
}

@Test
Expand All @@ -129,15 +129,15 @@ public void testZonalStatsWithNoData() throws IOException, FactoryException, Par

actual = RasterBandAccessors.getZonalStats(raster, geom, 1, "mean", true);
expected = 226.5599;
assertEquals(expected, actual, 1E-4);
assertEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getZonalStats(raster, geom, 1, "count");
expected = 14184.0;
assertEquals(expected, actual, 0.1d);

actual = RasterBandAccessors.getZonalStats(raster, geom, "variance");
expected = 5606.4233;
assertEquals(expected, actual, 1E-4);
assertEquals(expected, actual, FP_TOLERANCE);

actual = RasterBandAccessors.getZonalStats(raster, geom, "max");
expected = 255.0;
Expand All @@ -149,7 +149,7 @@ public void testZonalStatsWithNoData() throws IOException, FactoryException, Par

actual = RasterBandAccessors.getZonalStats(raster, geom, 1, "sd", true);
expected = 74.8760;
assertEquals(expected, actual, 1E-4);
assertEquals(expected, actual, FP_TOLERANCE);
}

@Test
Expand All @@ -160,7 +160,7 @@ public void testZonalStatsAll() throws IOException, FactoryException, ParseExcep

double[] actual = RasterBandAccessors.getZonalStatsAll(raster, geom, 1, false);
double[] expected = new double[] {184792.0, 1.0690406E7, 57.8510, 0.0, 0.0, 92.1327, 8488.4480, 0.0, 255.0};
assertArrayEquals(expected, actual, 1E-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);
}

@Test
Expand All @@ -171,7 +171,7 @@ public void testZonalStatsAllWithNoData() throws IOException, FactoryException,

double[] actual = RasterBandAccessors.getZonalStatsAll(raster, geom, 1, true);
double[] expected = new double[] {14184.0, 3213526.0, 226.5599, 255.0, 255.0, 74.8760, 5606.4233, 1.0, 255.0};
assertArrayEquals(expected, actual, 1E-4d);
assertArrayEquals(expected, actual, FP_TOLERANCE);
}

@Test
Expand All @@ -185,7 +185,7 @@ public void testZonalStatsAllWithEmptyRaster() throws FactoryException, ParseExc

double[] actual = RasterBandAccessors.getZonalStatsAll(raster, geom, 1, true);
double[] expected = new double[] {13.0, 114.0, 8.7692, 9.0, 11.0, 4.7285, 22.3589, 1.0, 16.0};
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 ca3dd5c

Please sign in to comment.