@Test
public void testDownscaling() throws Exception {

    final Grid scaledGrid = Downscaling.create(sourceGrid, 2);
    final GridDef scaledGridDef = scaledGrid.getGridDef();
    final GridDef sourceGridDef = sourceGrid.getGridDef();
    final int sourceW = sourceGridDef.getWidth();
    final int sourceH = sourceGridDef.getHeight();
    assertEquals(sourceW / 2, scaledGridDef.getWidth());
    assertEquals(sourceH / 2, scaledGridDef.getHeight());
    assertEquals(sourceGridDef.getEasting(), scaledGridDef.getEasting(), 1e-10);
    assertEquals(sourceGridDef.getNorthing(), scaledGridDef.getNorthing(), 1e-10);
    assertEquals(sourceGridDef.getResolutionX() * 2, scaledGridDef.getResolutionX(), 1e-10);
    assertEquals(sourceGridDef.getResolutionY() * 2, scaledGridDef.getResolutionY(), 1e-10);
    assertEquals(0.25, scaledGrid.getSampleDouble(0, 0), 1.0e-10);
    assertEquals(0.40, scaledGrid.getSampleDouble(1, 0), 1.0e-10);
    assertEquals(0.20, scaledGrid.getSampleDouble(2, 0), 1.0e-10);
    assertEquals(0.40, scaledGrid.getSampleDouble(3, 0), 1.0e-10);
    //
    assertEquals(0.20, scaledGrid.getSampleDouble(0, 1), 1.0e-10);
    assertEquals(0.20, scaledGrid.getSampleDouble(1, 1), 1.0e-10);
    assertEquals(0.30, scaledGrid.getSampleDouble(2, 1), 1.0e-10);
    assertTrue(Double.isNaN(scaledGrid.getSampleDouble(3, 1)));
}