Author: desruisseaux Date: Sat Jul 29 14:14:22 2017 New Revision: 1803372 URL: http://svn.apache.org/viewvc?rev=1803372&view=rev Log: Test consolidations. The tests are not yet enabled.
Added: sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/PixelIteratorTest.java - copied, changed from r1803371, sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTest.java Removed: sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/DefaultReadOnlyTest.java sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTest.java sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTestUtilities.java sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/ReadOnlyTest.java Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/iterator/PixelIterator.java sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTestImage.java sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java Modified: sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/iterator/PixelIterator.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/iterator/PixelIterator.java?rev=1803372&r1=1803371&r2=1803372&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/iterator/PixelIterator.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-raster/src/main/java/org/apache/sis/iterator/PixelIterator.java [UTF-8] Sat Jul 29 14:14:22 2017 @@ -45,8 +45,8 @@ import org.opengis.coverage.grid.Sequenc * * Moreover comportment not specify if iterator exceed image limits. * - * @author Rémi Marechal (Geomatys). - * @author Martin Desruisseaux (Geomatys). + * @author Rémi Marechal (Geomatys) + * @author Martin Desruisseaux (Geomatys) */ abstract class PixelIterator implements Closeable { @@ -54,7 +54,7 @@ abstract class PixelIterator implements * Define boundary, in pixel coordinates, of area traveled by this PixeIterator. * @see #getBoundary(boolean) */ - protected final RectIter areaIterate; + final RectIter areaIterate; /** * Define boundary, in pixel coordinates, of iterated object. @@ -66,58 +66,58 @@ abstract class PixelIterator implements * Tile index of iterated object. * note : raster is considered as image of one tile. */ - protected final RectIter tileIndexArea; + final RectIter tileIndexArea; /** * Size of tiles from iterated object. */ - protected final Dimension tileSize; + final Dimension tileSize; /** * Current raster which is followed by Iterator. */ - protected Raster currentRaster; + Raster currentRaster; /** * RenderedImage which is followed by Iterator. */ - protected final RenderedImage renderedImage; + final RenderedImage renderedImage; // /** * Number of band. */ - protected final int fixedNumBand; + final int fixedNumBand; /** * Number of raster band. * WARNING ! this is used a bit everywhere in iterator as a 'updateTileRaster' flag. */ - protected int rasterNumBand; + int rasterNumBand; /** * Current band position in this current raster. */ - protected int band; + int band; /** * {@link SampleModel} from the iterate object. */ - protected final SampleModel currentSampleModel; + final SampleModel currentSampleModel; //-- Iteration attributs /** * Stored position of upper right corner of current traveled raster. - * Generaly when this values are reach an update of the current + * Generally when this values are reach an update of the current * traveled raster is effectuate. */ - protected int currentRasterMaxX; - protected int currentRasterMaxY; + int currentRasterMaxX; + int currentRasterMaxY; /** * Current Tile index of current traveled raster. */ - protected int tX; - protected int tY; + int tX; + int tY; /** * Create raster iterator to follow from minX, minY raster and rectangle intersection coordinate. Modified: sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTestImage.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTestImage.java?rev=1803372&r1=1803371&r2=1803372&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTestImage.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTestImage.java [UTF-8] Sat Jul 29 14:14:22 2017 @@ -32,7 +32,7 @@ import java.util.Vector; * * @author Remi Marechal (Geomatys). */ -public class IteratorTestImage implements WritableRenderedImage { +final class IteratorTestImage implements WritableRenderedImage { private final int minx; private final int miny; @@ -53,21 +53,21 @@ public class IteratorTestImage implement public IteratorTestImage(final int minx, final int miny, final int width, final int height, final int tilesWidth, final int tilesHeight, final int tileGridXOffset, final int tileGridYOffset, - final SampleModel sampleM) { - + final SampleModel sampleM) + { this.minx = minx; this.miny = miny; this.width = width; this.height = height; this.tileSize = new Dimension(tilesWidth, tilesHeight); - numxtile = (int) Math.ceil(width / (double) tilesWidth); - numytile = (int) Math.ceil(height / (double) tilesHeight); + numxtile = (int) StrictMath.ceil(width / (double) tilesWidth); + numytile = (int) StrictMath.ceil(height / (double) tilesHeight); sm = sampleM; tgXo = tileGridXOffset; tgYo = tileGridYOffset; tiles = new WritableRaster[numxtile * numytile]; - minTx = (int) Math.floor((tgXo - minx) / (double)tileSize.width); - minTy = (int) Math.floor((tgYo - miny) / (double)tileSize.height); + minTx = (int) StrictMath.floor((tgXo - minx) / (double)tileSize.width); + minTy = (int) StrictMath.floor((tgYo - miny) / (double)tileSize.height); } @@ -233,8 +233,8 @@ public class IteratorTestImage implement } private WritableRaster getTileFromPixCoords(final int x, final int y) { - final int tx = Math.floorDiv((x - tgXo), tileSize.width); - final int ty = Math.floorDiv((y - tgYo) , tileSize.height); + final int tx = StrictMath.floorDiv((x - tgXo), tileSize.width); + final int ty = StrictMath.floorDiv((y - tgYo), tileSize.height); return getWritableTile(tx, ty); } } Copied: sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/PixelIteratorTest.java (from r1803371, sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTest.java) URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/PixelIteratorTest.java?p2=sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/PixelIteratorTest.java&p1=sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTest.java&r1=1803371&r2=1803372&rev=1803372&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/IteratorTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-raster/src/test/java/org/apache/sis/iterator/PixelIteratorTest.java [UTF-8] Sat Jul 29 14:14:22 2017 @@ -16,911 +16,1017 @@ */ package org.apache.sis.iterator; +import java.awt.Point; import java.awt.Rectangle; +import java.awt.image.DataBuffer; +import java.awt.image.PixelInterleavedSampleModel; import java.awt.image.Raster; -import java.awt.image.RenderedImage; import java.awt.image.WritableRaster; +import java.awt.image.WritableRenderedImage; +import java.util.Arrays; +import org.opengis.coverage.grid.SequenceType; +import org.apache.sis.test.DependsOnMethod; import org.apache.sis.test.TestCase; -import org.junit.Assert; -import static org.junit.Assert.assertTrue; import org.junit.Ignore; import org.junit.Test; +import static org.junit.Assert.*; + + /** - * Reading-only tests from any PixelIterator. + * Base class of {@link PixelIterator} tests. * - * @author Rémi Maréchal (Geomatys). + * @author Rémi Maréchal (Geomatys) + * @author Martin Desruisseaux (Geomatys) */ -public abstract class IteratorTest extends TestCase{ - +public strictfp class PixelIteratorTest extends TestCase { /** - * {@code PixelIterator} which will be tested. + * The pixel iterator being tested. + * This field is initialized by a call to one of the {@code createPixelIterator(…)} methods. */ - protected PixelIterator pixIterator; + private PixelIterator iterator; /** - * Raster use to test {@code PixelIterator}. + * The raster or image data type as one of the {@link DataBuffer} constants. */ - protected WritableRaster rasterTest; + private final int dataType; /** - * Rendered Image use to test {@code PixelIterator}. + * <var>x</var> coordinate of upper left corner in raster or image. */ - protected IteratorTestImage renderedImage; + private int xmin; /** - * X coordinate from upper left corner {@link #rasterTest} or {@link #renderedImage}. + * <var>y</var> coordinate of upper left corner in raster or image. */ - protected int minx; + private int ymin; /** - * Y coordinate from upper left corner {@link #rasterTest} or {@link #renderedImage}. + * Number of pixels along the <var>x</var> axis in raster or image. */ - protected int miny; + private int width; /** - * {@link #rasterTest} or {@link #renderedImage} width. + * Number of pixels along the <var>y</var> axis in raster or image. */ - protected int width; + private int height; /** - * {@link #rasterTest} or {@link #renderedImage} height. + * Number of bands in the raster or image. */ - protected int height; + private int numBands; /** - * {@link #rasterTest} or {@link #renderedImage} band number. + * Number of pixels along the <var>x</var> axis of each tile in image tiles. + * This is zero if the tests are performed on a raster instead than a tiled image. */ - protected int numBand; + private int tileWidth; /** - * {@link #renderedImage} tiles width. + * Number of pixels along the <var>y</var> axis of each tile in image tiles. + * This is zero if the tests are performed on a raster instead than a tiled image. */ - protected int tilesWidth; + private int tileHeight; /** - * {@link #renderedImage} tiles height. + * The expected values as a flat, row-major array. The content of this array is a copy + * of the sample values stored in the raster or image used as a source of test data. */ - protected int tilesHeight; - - - public IteratorTest() { - } + private float[] expected; /** - * Affect an appropriate {@code Raster} on {@link #rasterTest} attribute relative to expected test. + * Creates a new test case for the given data type. * - * @param minx {@link #rasterTest} X coordinate from upper left corner. - * @param miny {@link #rasterTest} Y coordinate from upper left corner. - * @param width {@link #rasterTest} width. - * @param height {@link #rasterTest} height. - * @param numBand {@link #rasterTest} band number. - * @param subArea {@code Rectangle} which represent {@link #rasterTest} sub area iteration. + * @param dataType the raster or image data type as one of the {@link DataBuffer} constants. */ - protected abstract void setRasterTest(int minx, int miny, int width, int height, int numBand, Rectangle subArea); + PixelIteratorTest(final int dataType) { + this.dataType = dataType; + } /** - * Affect an appropriate {@code PixelIterator} on {@link #pixIterator} attribute, relative to expected test. - * - * @param raster {@code Raster} which will be followed by {@link #pixIterator}. + * Creates a new test case. */ - protected abstract void setPixelIterator(Raster raster); + public PixelIteratorTest() { + this(DataBuffer.TYPE_INT); + } /** - * Affect an appropriate {@code PixelIterator} on {@link #pixIterator} attribute, relative to expected test. + * Creates a {@code WritableRaster} to use as the source of test data. + * The raster is filled with arbitrary sample values. * - * @param renderedImage {@code RenderedImage} which will be followed by {@link #pixIterator}. - */ - protected abstract void setPixelIterator(RenderedImage renderedImage); - - /** - * Affect an appropriate {@code PixelIterator} on {@link #pixIterator} attribute, relative to expected test. + * <p><b>Pre-conditions:</b> + * before invocation, the {@link #xmin}, {@link #ymin}, {@link #width}, {@link #height} and {@link #numBands} + * fields must be initialized.</p> * - * @param raster {@code Raster} which will be followed by {@link #pixIterator}. - * @param subArea {@code Rectangle} which represent {@link #rasterTest} sub area iteration. + * @param subArea the raster subarea on which to perform iteration, or {@code null} for the whole area. + * @return a raster filled with arbitrary sample values. */ - protected abstract void setPixelIterator(final Raster raster, final Rectangle subArea); + private WritableRaster createRaster(final Rectangle subArea) { + final int xmax = xmin + width; // Maximum value is exclusive. + final int ymax = ymin + height; + final int subMinX, subMinY, subMaxX, subMaxY; + if (subArea == null) { + subMinX = xmin; + subMinY = ymin; + subMaxX = xmax; + subMaxY = ymax; + } else { + subMinX = StrictMath.max(xmin, subArea.x); + subMinY = StrictMath.max(ymin, subArea.y); + subMaxX = StrictMath.min(xmax, subArea.x + subArea.width); + subMaxY = StrictMath.min(ymax, subArea.y + subArea.height); + } + expected = new float[(subMaxX - subMinX) * (subMaxY - subMinY) * numBands]; + final WritableRaster raster = Raster.createWritableRaster(new PixelInterleavedSampleModel(dataType, + width, height, numBands, width * numBands, new int[] {0,1,2}), new Point(xmin, ymin)); + /* + * At this point, all data structures have been created an initialized to zero sample values. + * Now fill the data structures with arbitrary values. + */ + int n = 0; + float value = (dataType == DataBuffer.TYPE_FLOAT) ? -2000.5f : 0f; + for (int y=ymin; y<ymax; y++) { + final boolean rowIncluded = (y >= subMinY && y < subMaxY); + for (int x=xmin; x<xmax; x++) { + final boolean included = rowIncluded && (x >= subMinX && x < subMaxX); + for (int b = 0; b < numBands; b++) { + raster.setSample(x, y, b, value); + if (included) { + expected[n++] = value; + } + value++; + } + } + } + assertEquals("Number of expected values", expected.length, n); + return raster; + } /** - * Affect an appropriate {@code PixelIterator} on {@link #pixIterator} attribute, relative to expected test. + * Creates a {@code RenderedImage} to use as the source of test data. + * The image is filled with arbitrary sample values. * - * @param renderedImage {@code RenderedImage} which will be followed by {@link #pixIterator}. - * @param subArea {@code Rectangle} which represent {@link #renderedImage} sub area iteration. - */ - protected abstract void setPixelIterator(final RenderedImage renderedImage, final Rectangle subArea); + * <p><b>Pre-conditions:</b> + * before invocation, the {@link #xmin}, {@link #ymin}, {@link #width}, {@link #height}, + * {@link #tileWidth}, {@link #tileHeight} and {@link #numBands} fields must be initialized.</p> + * + * @param subArea the image subarea on which to perform iteration, or {@code null} for the whole area. + * @return an image filled with arbitrary sample values. + */ + private WritableRenderedImage createImage(final Rectangle subArea) { + final int numXTiles = (width + tileWidth -1) / tileWidth; + final int numYTiles = (height + tileHeight-1) / tileHeight; + final int xmax = xmin + width; // Maximum value is exclusive. + final int ymax = ymin + height; + final int subMinX, subMinY, subMaxX, subMaxY; + if (subArea == null) { + subMinX = xmin; + subMinY = ymin; + subMaxX = xmax; + subMaxY = ymax; + } else { + subMinX = StrictMath.max(xmin, subArea.x); + subMinY = StrictMath.max(ymin, subArea.y); + subMaxX = StrictMath.min(xmax, subArea.x + subArea.width); + subMaxY = StrictMath.min(ymax, subArea.y + subArea.height); + } + expected = new float[(subMaxX - subMinX) * (subMaxY - subMinY) * numBands]; + final IteratorTestImage image = new IteratorTestImage(xmin, ymin, width, height, tileWidth, tileHeight, xmin+tileWidth, ymin+tileHeight, + new PixelInterleavedSampleModel(dataType, tileWidth, tileHeight, numBands, tileWidth * numBands, new int[] {0,1,2})); + /* + * At this point, all data structures have been created an initialized to zero sample values. + * Now fill the data structures with arbitrary values. We fill them tile-by-tile. + */ + int n = 0; + float value = (dataType == DataBuffer.TYPE_FLOAT) ? -200.5f : 0f; + for (int j=0; j<numYTiles; j++) { + for (int i=0; i<numXTiles; i++) { + final int yNextTile = ymin + (j+1) * tileHeight; + for (int y = yNextTile - tileHeight; y < yNextTile; y++) { + final boolean rowIncluded = (y >= subMinY && y < subMaxY); + final int xNextTile = xmin + (i+1) * tileWidth; + for (int x = xNextTile - tileWidth; x < xNextTile; x++) { + final boolean included = rowIncluded && (x >= subMinX && x < subMaxX); + for (int b = 0; b < numBands; b++) { + image.setSample(x, y, b, value); + if (included) { + expected[n++] = value; + } + value++; + } + } + } + } + } + assertEquals("Number of expected values", expected.length, n); + return image; + } /** - * Fill table use to valid tests. - * Affect value at index in test table. + * Creates a {@code PixelIterator} for the full area of given raster. + * The iterator shall be assigned to the {@link #iterator} field. * - * @param index table index. - * @param value to insert in test table. + * <p>The default implementation creates read-only iterators. + * Tests for read-write iterators need to override.</p> + * + * @param raster the data on which to perform iteration. */ - protected abstract void setTabTestValue(final int index, final double value); + void createPixelIterator(WritableRaster raster) { + iterator = PixelIteratorFactory.createReadOnlyIterator(raster); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + } /** - * Compare two table. + * Creates a {@code PixelIterator} for a sub-area of given raster. + * The iterator shall be assigned to the {@link #iterator} field. * - * Each PixelIterator test have two tables. - * Table witch contains expected values and another table contains {@code PixelIterator} iteration result. - * Test is validate if two table contains same values. + * <p>The default implementation creates read-only iterators. + * Tests for read-write iterators need to override.</p> * - * @return true if these table are equals else false. + * @param raster the data on which to perform iteration. + * @param subArea the boundary of the raster sub-area where to perform iteration. */ - protected abstract boolean compareTab(); + void createPixelIterator(WritableRaster raster, Rectangle subArea) { + iterator = PixelIteratorFactory.createReadOnlyIterator(raster, subArea); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + } /** - * Affect an appropriate {@code RenderedImage} on {@link #renderedImage} attribute relative to expected test. + * Creates a {@code PixelIterator} for the full area of given image. + * The iterator shall be assigned to the {@link #iterator} field. * - * @param minx {@link #renderedImage} X coordinate from upper left corner. - * @param miny {@link #renderedImage} Y coordinate from upper left corner. - * @param width {@link #renderedImage} width. - * @param height {@link #renderedImage} height. - * @param tilesWidth {@link #renderedImage} tiles width. - * @param tilesHeight {@link #renderedImage} tiles height. - * @param numBand {@link #renderedImage} band number. - * @param areaIterate {@code Rectangle} which represent {@link #renderedImage} sub area iteration. - */ - protected abstract void setRenderedImgTest(int minx, int miny, int width, int height, - int tilesWidth, int tilesHeight, int numBand, Rectangle areaIterate); - - /** - * Return {@link #renderedImage} or {@link #rasterTest} data type. + * <p>The default implementation creates read-only iterators. + * Tests for read-write iterators need to override.</p> * - * @return {@link #renderedImage} or {@link #rasterTest} data type. + * @param image the data on which to perform iteration. */ - protected abstract int getDataBufferType(); + void createPixelIterator(WritableRenderedImage image) { + iterator = PixelIteratorFactory.createReadOnlyIterator(image); + } /** - * Create appropriate table about "writable" tests. + * Creates a {@code PixelIterator} for the full area of given image. + * The iterator shall be assigned to the {@link #iterator} field. + * + * <p>The default implementation creates read-only iterators. + * Tests for read-write iterators need to override.</p> * - * @param length tests tables length. + * @param image the data on which to perform iteration. + * @param subArea the boundary of the image sub-area where to perform iteration. */ - protected abstract void createTable(int length); + void createPixelIterator(WritableRenderedImage image, Rectangle subArea) { + iterator = PixelIteratorFactory.createReadOnlyIterator(image, subArea); + } /** - * Fill reference table use to valid tests. - * Affect value at index in test table. + * Iterates over all values returned by the current {@link #iterator} and compares with expected values. * - * @param index table index. - * @param value to insert in reference table. + * @param verifyIndices whether to verify also iterator {@code getX()} and {@code getY()} return values. + * This is usually {@code true} if an only if the iterator cover the full raster area. */ - protected abstract void setTabRefValue(int index, double value); + private void verifyIteration(final boolean verifyIndices) { + int i = 0; + while (iterator.next()) { + final float e = expected[i++]; + final float a = iterator.getSampleFloat(); + if (Float.floatToRawIntBits(a) != Float.floatToRawIntBits(e)) { + fail("Pixel iteration at index " + i + ": expected " + e + " but got " + a); + } + if (verifyIndices) { + final int p = i / numBands; + assertEquals("x", (p % width) + xmin, iterator.getX()); + assertEquals("y", (p / width) + ymin, iterator.getY()); + } + } + assertEquals("Too few elements in iteration.", expected.length, i); + } -////////////////////////////////////Raster tests///////////////////////////////// /** - * Test if iterator transverse all raster positions with different minX and maxY coordinates. - * Also test rewind function. + * Tests iteration over all pixels in a single raster. + * This method uses different (<var>x</var>,<var>y</var>) origins. + * Tests also {@link PixelIterator#rewind()}. */ @Test - public void differentMinRasterReadTest() { - width = 16; - height = 16; - minx = 0; - miny = 0; - numBand = 3; - setRasterTest(minx, miny, width, height, numBand, null); - setPixelIterator(rasterTest); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @Ignore + public void testOnRaster() { + xmin = 0; + ymin = 0; + width = 10; + height = 12; + numBands = 3; + createPixelIterator(createRaster(null)); + verifyIteration(true); - minx = 3; - minx = 5; - setRasterTest(minx, miny, width, height, numBand, null); - setPixelIterator(rasterTest); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + xmin = 3; + ymin = 5; + createPixelIterator(createRaster(null)); + verifyIteration(true); - minx = -3; - miny = 5; - setRasterTest(minx, miny, width, height, numBand, null); - setPixelIterator(rasterTest); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + xmin = -3; + ymin = 5; + height = 9; + createPixelIterator(createRaster(null)); + verifyIteration(true); - minx = 3; - miny = -5; - setRasterTest(minx, miny, width, height, numBand, null); - setPixelIterator(rasterTest); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + xmin = 3; + ymin = -5; + height = 7; + createPixelIterator(createRaster(null)); + verifyIteration(true); - minx = -3; - miny = -5; - setRasterTest(minx, miny, width, height, numBand, null); - setPixelIterator(rasterTest); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + xmin = -3; + ymin = -5; + width = 7; + createPixelIterator(createRaster(null)); + verifyIteration(true); - pixIterator.rewind(); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + iterator.rewind(); + verifyIteration(true); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on upper left raster corner. + * Tests iteration over a sub-area in a single raster. + * This test iterates in the upper-left corner of the raster. */ @Test @Ignore - public void rectUpperLeftRasterReadTest() { + @DependsOnMethod("testOnRaster") + public void testOnRasterUpperLeft() { + xmin = 5; + ymin = 7; + width = 12; + height = 15; + numBands = 3; final Rectangle subArea = new Rectangle(4, 6, 5, 4); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - setPixelIterator(rasterTest, subArea); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + createPixelIterator(createRaster(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on upper right raster corner. + * Tests iteration over a sub-area in a single raster. + * This test iterates in the upper-right corner of the raster. */ @Test @Ignore - public void rectUpperRightRasterReadTest() { + @DependsOnMethod("testOnRaster") + public void testOnRasterUpperRight() { + width = 15; + height = 14; + xmin = 6; + ymin = 9; + numBands = 3; final Rectangle subArea = new Rectangle(16, 6, 10, 6); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - setPixelIterator(rasterTest, subArea); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + createPixelIterator(createRaster(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on lower right raster corner. + * Tests iteration over a sub-area in a single raster. + * This test iterates in the lower-right corner of the raster. */ @Test @Ignore - public void rectLowerRightRasterReadTest() { + @DependsOnMethod("testOnRaster") + public void testOnRasterLowerRight() { + xmin = 6; + ymin = 7; + width = 15; + height = 16; + numBands = 3; final Rectangle subArea = new Rectangle(14, 20, 15, 9); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - setPixelIterator(rasterTest, subArea); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + createPixelIterator(createRaster(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on lower left raster corner. + * Tests iteration over a sub-area in a single raster. + * This test iterates in the lower-left corner of the raster. */ @Test @Ignore - public void rectLowerLeftRasterReadTest() { + @DependsOnMethod("testOnRaster") + public void testOnRasterLowerLeft() { + xmin = 4; + ymin = 6; + width = 16; + height = 15; + numBands = 3; final Rectangle subArea = new Rectangle(2, 12, 10, 6); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - setPixelIterator(rasterTest, subArea); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + createPixelIterator(createRaster(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is within raster area. + * Tests iteration over a sub-area in a single raster. + * Tests also {@link PixelIterator#rewind()}. */ @Test @Ignore - public void rasterContainsRectReadTest() { + @DependsOnMethod("testOnRaster") + public void testOnRasterSubArea() { + xmin = 5; + ymin = 7; + width = 17; + height = 16; + numBands = 3; final Rectangle subArea = new Rectangle(10, 9, 8, 6); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - setPixelIterator(rasterTest, subArea); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + createPixelIterator(createRaster(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(false); - pixIterator.rewind(); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + iterator.rewind(); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area contains all raster area. + * Tests iteration over a sub-area that actually contains all the raster area. + * Tests also {@link PixelIterator#rewind()}. */ @Test @Ignore - public void rectContainsRasterReadTest() { + @DependsOnMethod("testOnRaster") + public void testOnRasterFullArea() { + xmin = 7; + ymin = 9; + width = 11; + height = 13; + numBands = 3; final Rectangle subArea = new Rectangle(2, 3, 25, 17); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - setPixelIterator(rasterTest, subArea); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + createPixelIterator(createRaster(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(true); } /** - * Test catching exception with x, y moveTo method coordinates out of raster boundary. + * Tests iteration over a sub-area that do not intersect the raster area. */ @Test @Ignore - public void unappropriateMoveToRasterTest() { - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, null); - setPixelIterator(rasterTest); - try{ - pixIterator.moveTo(2, 3, 0); - Assert.fail("test should had failed"); - }catch(Exception e){ - //ok - } - - try{ - pixIterator.moveTo(9, 10, -1); - Assert.fail("test should had failed"); - }catch(Exception e){ - //ok - } - - try{ - pixIterator.moveTo(9, 10, 500); - Assert.fail("test should had failed"); - }catch(Exception e){ - //ok - } + @DependsOnMethod("testOnRaster") + public void testOnRasterEmptyArea() { + width = 7; + height = 10; + xmin = 6; + ymin = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-17, -20, 5, 15); + createPixelIterator(createRaster(subArea), subArea); + assertEquals("Expected an empty set of values.", 0, expected.length); + verifyIteration(true); } /** - * Test catching exception with rectangle which don't intersect raster area. + * Verifies that invoking {@link PixelIterator#moveTo(int, int, int)} with illegal indices causes + * an exception to be thrown. */ @Test - public void unappropriateRectRasterTest() { - final Rectangle subArea = new Rectangle(-17, -20, 5, 15); - numBand = 3; - width = 16; - height = 16; - minx = 5; - miny = 7; - setRasterTest(minx, miny, width, height, numBand, subArea); - try{ - setPixelIterator(rasterTest, subArea); - Assert.fail("test should had failed"); - }catch(Exception e){ - //ok + @Ignore + public void testIllegalMoveOnRaster() { + xmin = 4; + ymin = 7; + width = 13; + height = 10; + numBands = 3; + createPixelIterator(createRaster(null)); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + try { + iterator.moveTo(2, 3, 0); + fail("Expected IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // ok + } + try { + iterator.moveTo(9, 10, -1); + fail("Expected IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // ok + } + try { + iterator.moveTo(9, 10, 500); + fail("Expected IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // ok } } - -//////////////////////////////Rendered image tests///////////////////////////////// - - /** - * Test if iterator transverse all raster positions with different minX and maxY coordinates. - * Also test rewind function. + * Tests iteration over all pixels in a tiled image. + * This method uses different (<var>x</var>,<var>y</var>) origins. + * Tests also {@link PixelIterator#rewind()}. */ @Test @Ignore - public void transversingAllReadTest() { - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, null); - setPixelIterator(renderedImage); + @DependsOnMethod("testOnRaster") + public void testOnImage() { + xmin = 0; + ymin = 0; + width = 100; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + xmin = 1; + ymin = -50; + createPixelIterator(createImage(null)); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); - minx = 1; - miny = -50; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, null); - setPixelIterator(renderedImage); - - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); - - pixIterator.rewind(); - comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + iterator.rewind(); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined within upper left renderedImage tile. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the upper-left corner of the image. + * The sub-area is small enough for the iteration to happen in a single tile. */ @Test @Ignore - public void rectUpperLeftWithinTileTest() { - final Rectangle rect = new Rectangle(-10, -20, 10, 30); - minx = -5; - miny = 5; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod({"testOnImage", "testOnRasterUpperLeft"}) + public void testOnTileUpperLeft() { + xmin = -5; + ymin = 5; + width = 40; + height = 30; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-10, -20, 10, 30); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined within upper right renderedImage tile. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the upper-right corner of the image. + * The sub-area is small enough for the iteration to happen in a single tile. */ @Test @Ignore - public void rectUpperRightWithinTileTest() { - final Rectangle rect = new Rectangle(90, -20, 30, 31); - minx = -5; - miny = 7; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod({"testOnImage", "testOnRasterUpperRight"}) + public void testOnTileUpperRight() { + xmin = 35; + ymin = 7; + width = 60; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(90, -20, 30, 31); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined within lower right renderedImage tile. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the lower-right corner of the image. + * The sub-area is small enough for the iteration to happen in a single tile. */ @Test @Ignore - public void rectLowerRightWithinTileTest() { - final Rectangle rect = new Rectangle(97, 40, 50, 50); - minx = 5; - miny = -7; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod({"testOnImage", "testOnRasterLowerRight"}) + public void testOnTileLowerRight() { + xmin = 55; + ymin = -7; + width = 40; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(97, 40, 50, 50); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined within lower left renderedImage tile. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the lower-left corner of the image. + * The sub-area is small enough for the iteration to happen in a single tile. */ @Test @Ignore - public void rectLowerLeftWithinTileTest() { - final Rectangle rect = new Rectangle(0, 34, 5, 50); - minx = 2; - miny = -15; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod({"testOnImage", "testOnRasterLowerLeft"}) + public void testOnTileLowerLeft() { + xmin = 2; + ymin = -15; + width = 30; + height = 40; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(0, 34, 5, 50); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is within image tile. + * Tests iteration over a sub-area in a tiled image. + * The sub-area is small enough for the iteration to happen in a single tile. */ @Test @Ignore - public void imageContainsRectWithinTileTest() { - final Rectangle rect = new Rectangle(16, 18, 8, 3); - minx = -5; - miny = 7; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod({"testOnImage", "testOnRasterSubArea"}) + public void testOnTileSubArea() { + xmin = -5; + ymin = 7; + width = 50; + height = 40; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(16, 18, 8, 3); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertEquals("getIterationDirection()", SequenceType.LINEAR, iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on upper left rendered image corner. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the upper-left corner of the image. + * The sub-area is large enough for covering more than one tile. */ @Test @Ignore - public void rectUpperLeftTest() { - final Rectangle rect = new Rectangle(-10, -20, 40, 30); - minx = -5; - miny = 5; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod("testOnTileUpperLeft") + public void testOnImageUpperLeft() { + xmin = -5; + ymin = 5; + width = 90; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-10, -20, 40, 30); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on upper right rendered image corner. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the upper-right corner of the image. + * The sub-area is large enough for covering more than one tile. */ @Test @Ignore - public void rectUpperRightTest() { - final Rectangle rect = new Rectangle(80, -20, 30, 50); - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod("testOnTileUpperRight") + public void testOnImageUpperRight() { + xmin = 20; + ymin = 0; + width = 80; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(80, -20, 30, 50); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on lower right rendered image corner. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the lower-right corner of the image. + * The sub-area is large enough for covering more than one tile. */ @Test @Ignore - public void rectLowerRightTest() { - final Rectangle rect = new Rectangle(80, 30, 50, 50); - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod("testOnTileLowerRight") + public void testOnImageLowerRight() { + xmin = 30; + ymin = 0; + width = 70; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(80, 30, 50, 50); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is defined on lower left rendered image corner. + * Tests iteration over a sub-area in a tiled image. + * This test iterates in the lower-left corner of the image. + * The sub-area is large enough for covering more than one tile. */ @Test @Ignore - public void rectLowerLeftTest() { - final Rectangle rect = new Rectangle(-20, 30, 50, 50); - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod("testOnTileLowerLeft") + public void testOnImageLowerLeft() { + xmin = 0; + ymin = 0; + width = 70; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-20, 30, 50, 50); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area is within image area. + * Tests iteration over a sub-area in a tiled image. + * The sub-area is large enough for covering more than one tile. */ @Test @Ignore - public void imageContainsRectTest() { - final Rectangle rect = new Rectangle(20, 10, 10, 10); - minx = -5; - miny = 7; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod("testOnTileSubArea") + public void testOnImageSubArea() { + xmin = -5; + ymin = 7; + width = 100; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(20, 10, 10, 10); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test if iterator transverse expected value in define area. - * Area contains all image area. + * Tests iteration over a sub-area in a tiled image. + * The sub-area is large enough for covering more than one tile. */ @Test @Ignore - public void rectContainsImageTest() { - final Rectangle rect = new Rectangle(-10, -10, 150, 80); - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - setPixelIterator(renderedImage, rect); - - int comp = 0; - while (pixIterator.next()) { - setTabTestValue(comp++, pixIterator.getSampleDouble()); - } - assertTrue(compareTab()); + @DependsOnMethod({"testOnImage", "testOnRasterFullArea"}) + public void testOnImageFullArea() { + xmin = 0; + ymin = 0; + width = 100; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-10, -10, 150, 80); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + assertNull("getIterationDirection()", iterator.getIterationDirection()); + verifyIteration(false); } /** - * Test catching exception with rectangle which don't intersect raster area. + * Tests iteration over a sub-area that do not intersect the image area. */ @Test @Ignore - public void unappropriateRectRITest() { - final Rectangle rect = new Rectangle(-100, -50, 5, 17); - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, 3, rect); - try{ - setPixelIterator(renderedImage, rect); - Assert.fail("test should had failed"); - }catch(IllegalArgumentException e){ - //ok - } + @DependsOnMethod("testOnRasterEmptyArea") + public void testOnImageEmptyArea() { + xmin = 0; + ymin = 0; + width = 20; + height = 10; + tileWidth = 15; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-100, -50, 5, 17); + createPixelIterator(createImage(subArea), subArea); + assertEquals("Expected an empty set of values.", 0, expected.length); + verifyIteration(true); } /** - * Test catching exception with x, y moveTo method coordinates out of raster boundary. + * Verifies that invoking {@link PixelIterator#moveTo(int, int, int)} with illegal indices causes + * an exception to be thrown. */ @Test @Ignore - public void unappropriateMoveToRITest() { - minx = 0; - miny = 0; - width = 100; - height = 50; - tilesWidth = 10; - tilesHeight = 5; - numBand = 3; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, numBand, null); - setPixelIterator(renderedImage); - try{ - pixIterator.moveTo(102, 53, 0); - Assert.fail("test should had failed"); - }catch(IllegalArgumentException e){ - //ok + @DependsOnMethod("testIllegalMoveOnRaster") + public void testIllegalMoveOnImage() { + xmin = 0; + ymin = 0; + width = 20; + height = 10; + tileWidth = 15; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + try { + iterator.moveTo(102, 53, 0); + fail("Expected IllegalArgumentException."); + } catch (IllegalArgumentException e) { + // ok } } /** - * Test catching exception with another next() method call, after have already traveled all the image. + * Verifies that invoking {@link PixelIterator#next()} after iteration end causes an exception to be thrown. */ @Test @Ignore - public void unappropriateMultiNextCallTest() { - minx = 0; - miny = 0; - width = 40; - height = 20; - tilesWidth = 10; - tilesHeight = 5; - numBand = 3; - setRenderedImgTest(minx, miny, width, height, tilesWidth, tilesHeight, numBand, null); - setPixelIterator(renderedImage); - while (pixIterator.next()) { - //-- do nothing, we want go to the end of the iteration - } + @DependsOnMethod("testOnImage") + public void testIllegalNext() { + xmin = 0; + ymin = 0; + width = 20; + height = 15; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + final Rectangle subArea = new Rectangle(-10, -10, 150, 80); + createPixelIterator(createImage(subArea), subArea); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + verifyIteration(false); try { - pixIterator.next(); - Assert.fail("test should had failed"); + iterator.next(); + fail("Expected IllegalStateException."); } catch (IllegalStateException e) { - //ok + // ok } } + /** + * Tests {@link PixelIterator#getX()} and {@link PixelIterator#getY()}. + */ + @Test + @Ignore + public void testGetXY() { + xmin = 56; + ymin = 1; + width = 40; + height = 32; + tileWidth = 10; + tileHeight = 8; + numBands = 3; + createPixelIterator(createImage(null)); + assertTrue("Expected a non-empty set of values.", expected.length != 0); + int i = 0; + for (int ty = 0; ty < height/tileHeight; ty++) { + for (int tx = 0; tx < width/tileWidth; tx++) { + for (int y = 0; y<tileHeight; y++) { + for (int x = 0; x<tileWidth; x++) { + assertTrue(iterator.next()); + assertEquals("x", tx*tileWidth + x + xmin, iterator.getX()); + assertEquals("y", ty*tileHeight + y + ymin, iterator.getY()); + assertEquals(expected[i], iterator.getSampleFloat(), 0f); + for (int b=1; b<numBands; b++) { + assertTrue(iterator.next()); + assertEquals(expected[i], iterator.getSampleFloat(), 0f); + } + } + } + } + } + assertEquals("Too few elements in iteration.", expected.length, i); + } + /** + * Moves the iterator to the given position and discards the {@link #expected} values prior that position. + * This method is used for implementation of {@code testMoveXXX()} methods. + */ + private void moveTo(int x, int y) { + iterator.moveTo(x, y, 0); + x -= xmin; + y -= ymin; + final int pixelIndex; + if (tileWidth == 0 && tileHeight == 0) { + pixelIndex = y*width + x; + } else { + final int tx = x / tileWidth; + final int ty = y / tileHeight; + final int numTileX = (width + tileWidth - 1) / tileWidth; + pixelIndex = ((ty * (numTileX - 1) + tx) * tileHeight + y - tx) * tileWidth + x; + } + expected = Arrays.copyOfRange(expected, pixelIndex * numBands, expected.length); + } /** - * Test about getNumBands methods + * Tests iteration after a call to {@link PixelIterator#moveTo(int, int, int)} in a raster. */ - public void numBandsTest() { - assertTrue(pixIterator.getNumBands() == 1); + @Test + @Ignore + public void testMoveIntoRaster() { + xmin = 5; + ymin = 7; + width = 16; + height = 13; + numBands = 3; + createPixelIterator(createRaster(null)); + moveTo(17, 15); + verifyIteration(false); } /** - * Compare 2 integer table. - * - * @param tabA table resulting raster iterate. - * @param tabB table resulting raster iterate. - * @return true if tables are identical. + * Tests iteration after a call to {@link PixelIterator#moveTo(int, int, int)} in a tiled image. */ - protected boolean compareTab(int[] tabA, int[] tabB) { - int length = tabA.length; - if (length != tabB.length) return false; - for (int i = 0; i<length; i++) { - if (tabA[i] != tabB[i]) { - return false; - } - } - return true; + @Test + @Ignore + @DependsOnMethod({"testOnImage", "testMoveIntoRaster"}) + public void testMoveIntoImage() { + xmin = -1; + ymin = 3; + width = 60; + height = 50; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + moveTo(17, 15); + verifyIteration(false); } /** - * Compare 2 double table. - * - * @param tabA table resulting raster iterate. - * @param tabB table resulting raster iterate. - * @return true if tables are identical. + * Tests iteration after a call to {@link PixelIterator#moveTo(int, int, int)} in a tiled image. */ - protected boolean compareTab(double[] tabA, double[] tabB) { - int length = tabA.length; - if (length != tabB.length) return false; - for (int i = 0; i<length; i++) { - if (tabA[i] != tabB[i]) return false; - } - return true; + @Test + @Ignore + @DependsOnMethod("testMoveIntoImage") + public void testMoveToUpperLeft() { + xmin = -1; + ymin = 3; + width = 30; + height = 25; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + moveTo(-1, 3); + verifyIteration(false); } /** - * Compare 2 float table. - * - * @param tabA table resulting raster iterate. - * @param tabB table resulting raster iterate. - * @return true if tables are identical. + * Tests iteration after a call to {@link PixelIterator#moveTo(int, int, int)} in a tiled image. */ - protected boolean compareTab(float[] tabA, float[] tabB) { - int length = tabA.length; - if (length != tabB.length) return false; - for (int i = 0; i<length; i++) { - if (tabA[i] != tabB[i]) return false; - } - return true; + @Test + @Ignore + @DependsOnMethod("testMoveIntoImage") + public void testMoveToUpperRight() { + xmin = 69; + ymin = 3; + width = 30; + height = 25; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + moveTo(98, 3); + verifyIteration(false); } /** - * Compare 2 short table. - * - * @param tabA table resulting raster iterate. - * @param tabB table resulting raster iterate. - * @return true if tables are identical. + * Tests iteration after a call to {@link PixelIterator#moveTo(int, int, int)} in a tiled image. */ - protected boolean compareTab(short[] tabA, short[] tabB) { - int length = tabA.length; - if (length != tabB.length) return false; - for (int i = 0; i<length; i++) { - if (tabA[i] != tabB[i]) return false; - } - return true; + @Test + @Ignore + @DependsOnMethod("testMoveIntoImage") + public void testMoveToLowerRight() { + xmin = 69; + ymin = 28; + width = 30; + height = 25; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + moveTo(98, 52); + verifyIteration(false); } /** - * Compare 2 byte table. - * - * @param tabA table resulting raster iterate. - * @param tabB table resulting raster iterate. - * @return true if tables are identical. + * Tests iteration after a call to {@link PixelIterator#moveTo(int, int, int)} in a tiled image. */ - protected boolean compareTab(byte[] tabA, byte[] tabB) { - int length = tabA.length; - if (length != tabB.length) return false; - for (int i = 0; i<length; i++) { - if (tabA[i] != tabB[i]) return false; - } - return true; + @Test + @Ignore + @DependsOnMethod("testMoveIntoImage") + public void testMoveToLowerLeft() { + xmin = -1; + ymin = 28; + width = 30; + height = 25; + tileWidth = 10; + tileHeight = 5; + numBands = 3; + createPixelIterator(createImage(null)); + moveTo(-1, 52); + verifyIteration(false); } } Modified: sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java?rev=1803372&r1=1803371&r2=1803372&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-referencing-by-identifiers/src/test/java/org/apache/sis/referencing/gazetteer/MilitaryGridReferenceSystemTest.java [UTF-8] Sat Jul 29 14:14:22 2017 @@ -175,9 +175,9 @@ public final strictfp class MilitaryGrid * The lowest 4 bits are the number of the row cycle (a cycle of 2000 km). The remaining bits tell which * rows are valid in that latitude band. */ - final int rowCycle = (int) Math.floor(ymin / (MilitaryGridReferenceSystem.GRID_SQUARE_SIZE * MilitaryGridReferenceSystem.GRID_ROW_COUNT)); - final int lowerRow = (int) Math.floor(ymin / MilitaryGridReferenceSystem.GRID_SQUARE_SIZE); // Inclusive - final int upperRow = (int) Math.ceil (ymax / MilitaryGridReferenceSystem.GRID_SQUARE_SIZE); // Exclusive + final int rowCycle = (int) StrictMath.floor(ymin / (MilitaryGridReferenceSystem.GRID_SQUARE_SIZE * MilitaryGridReferenceSystem.GRID_ROW_COUNT)); + final int lowerRow = (int) StrictMath.floor(ymin / MilitaryGridReferenceSystem.GRID_SQUARE_SIZE); // Inclusive + final int upperRow = (int) StrictMath.ceil (ymax / MilitaryGridReferenceSystem.GRID_SQUARE_SIZE); // Exclusive assertTrue("rowCycle", rowCycle >= 0 && rowCycle <= MilitaryGridReferenceSystem.Decoder.NORTHING_BITS_MASK); assertTrue("lowerRow", lowerRow >= 0); assertTrue("upperRow", upperRow >= 0); Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java?rev=1803372&r1=1803371&r2=1803372&view=diff ============================================================================== --- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java [UTF-8] (original) +++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/measure/ConventionalUnitTest.java [UTF-8] Sat Jul 29 14:14:22 2017 @@ -186,9 +186,9 @@ public final strictfp class Conventional verify (Units.CUBIC_METRE, Units.CUBIC_METRE .divide (1E+9), "mm³", 1E-9); assertSame(Units.HOUR, Units.SECOND.multiply(3600)); - assertSame(Units.DEGREE, Units.RADIAN.multiply(Math.PI/180)); - assertSame(Units.GRAD, Units.RADIAN.multiply(Math.PI/200)); - assertSame(Units.ARC_SECOND, Units.RADIAN.multiply(Math.PI / (180*60*60))); + assertSame(Units.DEGREE, Units.RADIAN.multiply(StrictMath.PI/180)); + assertSame(Units.GRAD, Units.RADIAN.multiply(StrictMath.PI/200)); + assertSame(Units.ARC_SECOND, Units.RADIAN.multiply(StrictMath.PI / (180*60*60))); assertSame(Units.MICRORADIAN, Units.RADIAN.divide(1E6)); assertSame(Units.GRAM, Units.KILOGRAM.divide(1E+3));