@Test
public void singleContourInVerticalGradient() {

    final int COVERAGE_COLS = 10;
    final int COVERAGE_ROWS = 2;
    
    final double CELL_SIZE = 100;
    
    final ReferencedEnvelope WORLD = new ReferencedEnvelope(
            1000, 1000 + COVERAGE_COLS * CELL_SIZE, 
            5000, 5000 + COVERAGE_ROWS * CELL_SIZE, null);
    
    final float DATA_MIN = 100;
    final float DATA_MAX = 200;
    
    GridCoverage2D cov = createVerticalGradient(
            COVERAGE_ROWS, COVERAGE_COLS, WORLD, DATA_MIN, DATA_MAX);
    
    final double levelValue = (DATA_MIN + DATA_MAX) / 2; 
    
    SimpleFeatureCollection fc = process.execute(
            cov, 0, new double[] {levelValue}, null, null, null, null, null);
    // Should be a single contour
    assertEquals(1, fc.size());
    
    SimpleFeatureIterator iter = fc.features();
    SimpleFeature feature = null;
    try {
        feature = iter.next();
    } finally {
        iter.close();
    }
    
    // Check contour value
    Double value = (Double) feature.getAttribute("value");
    assertEquals(levelValue, value, TOL);
            
    LineString contour = (LineString) feature.getDefaultGeometry();
    Coordinate[] coords = contour.getCoordinates();
            
    // Contour should have had co-linear vertices removed by default
    assertEquals(2, coords.length);
            
    // Contour end-point X ordinates should be within half cell-width of
    // coverage X extrema
    double minX = Math.min(coords[0].x, coords[1].x);
    assertEquals(WORLD.getMinX(), minX, CELL_SIZE / 2 + TOL);
    double maxX = Math.max(coords[0].x, coords[1].x);
    assertEquals(WORLD.getMaxX(), maxX, CELL_SIZE / 2 + TOL);
            
    // Contour Y ordinate should be at mid-Y of coverage and
    // contour should be horizontal
    double expectedY = (WORLD.getMinY() + WORLD.getMaxY()) / 2;
    assertEquals(expectedY, coords[0].y, TOL);
    assertEquals(expectedY, coords[1].y, TOL);
}