Class TransformTestCase
- java.lang.Object
-
- org.opengis.test.TestCase
-
- org.opengis.test.referencing.TransformTestCase
-
public abstract class TransformTestCase extends TestCase
Base class for tests ofMathTransformimplementations. Subclasses shall assign a value to thetransformfield before to invoke any method in this class. The assigned transform must support theMathTransform.transform(DirectPosition,DirectPosition)method. By default the other transform methods (working on arrays) are assumed supported, but their tests can be disabled on a case-by-case basis by setting someis<Operation>Supportedfields tofalse.Once the fields are assigned their values, subclasses can invoke any of the
verifymethods in their test methods. Callers must supply the input coordinate points to be used for testing purpose, since the range of valid values is usually transform-dependent.Methods in this class do not validate the transform. It is caller responsibility to validate the transform if wanted.
- Since:
- 2.2
- Version:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanisDoubleToDoubleSupportedtrueifMathTransform.transform(double[],int,double[],int,int)is supported.protected booleanisDoubleToFloatSupportedtrueifMathTransform.transform(double[],int,float[],int,int)is supported.protected booleanisFloatToDoubleSupportedtrueifMathTransform.transform(float[],int,double[],int,int)is supported.protected booleanisFloatToFloatSupportedtrueifMathTransform.transform(float[],int,float[],int,int)is supported.protected booleanisInverseTransformSupportedtrueifMathTransform.inverse()is supported.protected booleanisOverlappingArraySupportedtrueif the destination array can be the same than the source array, and the source and target region of the array can overlap.private static intPOINTS_OFFSETThe maximal offset (in number of coordinate points), exclusive, to apply when testingMathTransform.transform(...)with overlapping arrays.protected doubletoleranceMaximum difference to be accepted when comparing a transformed ordinate value with the expected one.protected MathTransformtransformThe transform being tested.
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransformTestCase()Creates a test case initialized to default values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertAllTestsEnabled()Ensures that allis<Operation>Supportedfields are set totrue.protected voidassertCoordinateEquals(java.lang.String message, double[] expected, double[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta.protected voidassertCoordinateEquals(java.lang.String message, double[] expected, float[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta.protected voidassertCoordinateEquals(java.lang.String message, float[] expected, double[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta.protected voidassertCoordinateEquals(java.lang.String message, float[] expected, float[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta.protected voidassertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta.private voidassertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.protected voidassertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta.private voidassertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.protected voidassertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta.private voidassertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.protected voidassertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta.private voidassertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.private static java.lang.StringformatComparaisonFailure(java.lang.String message, int dimension, java.lang.Object expectedPts, int expectedOffset, java.lang.Object actualPts, int actualOffset, int failureIndex, java.lang.Number delta, int reportedIndex)Formats an error message for a comparison failure.protected doubletolerance(double ordinate)Returns the tolerance threshold for comparing the given ordinate value.protected float[]verifyConsistency(float[] sourceFloats)Transforms coordinates using various versions ofMathTransform.transform(...)and verifies that they produce the same numerical values.protected voidverifyInverse(double[] coordinates)Transforms the given coordinates, applies the inverse transform and compares with the original values.protected voidverifyInverse(float[] coordinates)Transforms the given coordinates, applies the inverse transform and compares with the original values.protected voidverifyTransform(double[] coordinates, double[] expected)Transforms the given coordinates and verifies that the result is equals (within a positive delta) to the expected ones.
-
-
-
Field Detail
-
POINTS_OFFSET
private static final int POINTS_OFFSET
The maximal offset (in number of coordinate points), exclusive, to apply when testingMathTransform.transform(...)with overlapping arrays. Higher values make the tests more extensive but slower. Small values like 8 are usually enough.- See Also:
- Constant Field Values
-
transform
protected MathTransform transform
The transform being tested. Subclasses should assign a value to this field, typically in some method annotated with JUnitBeforeannotation.Subclasses should consider setting a tolerance threshold value together with the transform.
- See Also:
tolerance
-
isDoubleToDoubleSupported
protected boolean isDoubleToDoubleSupported
trueifMathTransform.transform(double[],int,double[],int,int)is supported. The default value istrue. Vendor can set this value tofalsein order to test a transform which is not fully implemented.
-
isFloatToFloatSupported
protected boolean isFloatToFloatSupported
trueifMathTransform.transform(float[],int,float[],int,int)is supported. The default value istrue. Vendor can set this value tofalsein order to test a transform which is not fully implemented.
-
isDoubleToFloatSupported
protected boolean isDoubleToFloatSupported
trueifMathTransform.transform(double[],int,float[],int,int)is supported. The default value istrue. Vendor can set this value tofalsein order to test a transform which is not fully implemented.
-
isFloatToDoubleSupported
protected boolean isFloatToDoubleSupported
trueifMathTransform.transform(float[],int,double[],int,int)is supported. The default value istrue. Vendor can set this value tofalsein order to test a transform which is not fully implemented.
-
isOverlappingArraySupported
protected boolean isOverlappingArraySupported
trueif the destination array can be the same than the source array, and the source and target region of the array can overlap. The default value istrue. Vendor can set this value tofalsein order to test a transform which is not fully implemented.
-
isInverseTransformSupported
protected boolean isInverseTransformSupported
trueifMathTransform.inverse()is supported.
-
tolerance
protected double tolerance
Maximum difference to be accepted when comparing a transformed ordinate value with the expected one. By default this threshold is absolute; no special computation is performed for taking in account the magnitude of the ordinate being compared. If a subclass needs to set a relative tolerance threshold instead than an absolute one, it should override thetolerance(double)method.The default value is 0, which means that strict equality will be required. Subclasses should set a more suitable tolerance threshold when transform is assigned a value.
- See Also:
transform,tolerance(double)
-
-
Method Detail
-
tolerance
protected double tolerance(double ordinate)
Returns the tolerance threshold for comparing the given ordinate value. The default implementation returns thetolerancevalue directly, thus implementing an absolute tolerance threshold. If a subclass needs a relative tolerance threshold instead, it can override this method as below:return tolerance * Math.abs(ordinate);- Parameters:
ordinate- The ordinate value being compared.- Returns:
- The absolute tolerance threshold to use for comparing the given ordinate.
-
assertAllTestsEnabled
protected void assertAllTestsEnabled()
Ensures that allis<Operation>Supportedfields are set totrue. This method can be invoked before testing a math transform which is expected to be fully implemented.
-
verifyTransform
protected void verifyTransform(double[] coordinates, double[] expected) throws TransformExceptionTransforms the given coordinates and verifies that the result is equals (within a positive delta) to the expected ones. If the difference between an expected and actual ordinate value is greater than the tolerance threshold, then the assertion fails.If
isInverseTransformSupportedistrue, then this method will also transform the expected coordinate points using the inverse transform and compare with the source coordinates.- Parameters:
coordinates- The coordinate points to transform.expected- The expect result of the transformation, ornullifcoordinatesis expected to be null.- Throws:
TransformException- if the transformation failed.
-
verifyInverse
protected void verifyInverse(double[] coordinates) throws TransformExceptionTransforms the given coordinates, applies the inverse transform and compares with the original values. If a difference between the expected and actual ordinate values is greater than the tolerance threshold, then the assertion fails.At the difference of
verifyTransform(double[],double[]), this method do not require an array of expected values. The expected values are calculated from the transform itself.- Parameters:
coordinates- The source coordinates to transform.- Throws:
TransformException- if at least one coordinate can't be transformed.
-
verifyInverse
protected void verifyInverse(float[] coordinates) throws TransformExceptionTransforms the given coordinates, applies the inverse transform and compares with the original values. If a difference between the expected and actual ordinate values is greater than the tolerance threshold, then the assertion fails.The default implementation delegates to
verifyInverse(double[]).- Parameters:
coordinates- The source coordinates to transform.- Throws:
TransformException- if at least one coordinate can't be transformed.
-
verifyConsistency
protected float[] verifyConsistency(float[] sourceFloats) throws TransformExceptionTransforms coordinates using various versions ofMathTransform.transform(...)and verifies that they produce the same numerical values. The values calculated byMathTransform.transform(DirectPosition,DirectPosition)are used as the reference. Other transform methods (operating on arrays) will be compared against that reference, unless their checks were disabled (see class javadoc for details).This method expects an array of
floatvalues instead thandoublefor making sure that theMathTransform.transform(float[], ...)andMathTransform.transform(double[], ...)methods produces the same numerical values. Thedoublevalues may show extra digits when formatted in base 10, but this is not significant if their IEEE 754 representation (which use base 2) are equivalent.This method does not verify the inverse transform. The later can be verified with
verifyInverse(float[])if wanted.- Parameters:
sourceFloats- The source coordinates to transform as an array offloatvalues.- Returns:
- The transformed coordinates, returned for convenience.
- Throws:
TransformException- if at least one coordinate can't be transformed.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(java.lang.String message, float[] expected, float[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the ordinate where the failure was found.- Parameters:
message- The message to print in case of failure.expected- The array of expected ordinate values.actual- The array of ordinate values to check against the expected ones.index- The index of the coordinate point being compared, for message formatting.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(java.lang.String message, float[] expected, double[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the ordinate where the failure was found.- Parameters:
message- The message to print in case of failure.expected- The array of expected ordinate values.actual- The array of ordinate values to check against the expected ones.index- The index of the coordinate point being compared, for message formatting.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(java.lang.String message, double[] expected, float[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the ordinate where the failure was found.- Parameters:
message- The message to print in case of failure.expected- The array of expected ordinate values.actual- The array of ordinate values to check against the expected ones.index- The index of the coordinate point being compared, for message formatting.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(java.lang.String message, double[] expected, double[] actual, int index, boolean strict)Asserts that a single coordinate is equal to the expected one within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the ordinate where the failure was found.- Parameters:
message- The message to print in case of failure.expected- The array of expected ordinate values.actual- The array of ordinate values to check against the expected ones.index- The index of the coordinate point being compared, for message formatting.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the coordinate where the failure was found.- Parameters:
message- The message to print in case of failure.dimension- The dimension of each coordinate points in the arrays.expectedPts- The array of expected coordinate values.expectedOffset- Index of the first valid ordinate in theexpectedPtsarray.actualPts- The array of coordinate values to check against the expected ones.actualOffset- Index of the first valid ordinate in theactualPtsarray.numPoints- Number of coordinate points to compare.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the coordinate where the failure was found.- Parameters:
message- The message to print in case of failure.dimension- The dimension of each coordinate points in the arrays.expectedPts- The array of expected coordinate values.expectedOffset- Index of the first valid ordinate in theexpectedPtsarray.actualPts- The array of coordinate values to check against the expected ones.actualOffset- Index of the first valid ordinate in theactualPtsarray.numPoints- Number of coordinate points to compare.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the coordinate where the failure was found.- Parameters:
message- The message to print in case of failure.dimension- The dimension of each coordinate points in the arrays.expectedPts- The array of expected coordinate values.expectedOffset- Index of the first valid ordinate in theexpectedPtsarray.actualPts- The array of coordinate values to check against the expected ones.actualOffset- Index of the first valid ordinate in theactualPtsarray.numPoints- Number of coordinate points to compare.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict)Asserts that coordinate values are equal to the expected ones within a positive delta. If the comparison fails, the given message is completed with the expected and actual values, and the index of the coordinate where the failure was found.- Parameters:
message- The message to print in case of failure.dimension- The dimension of each coordinate points in the arrays.expectedPts- The array of expected coordinate values.expectedOffset- Index of the first valid ordinate in theexpectedPtsarray.actualPts- The array of coordinate values to check against the expected ones.actualOffset- Index of the first valid ordinate in theactualPtsarray.numPoints- Number of coordinate points to compare.strict-truefor ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
private void assertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.
-
assertCoordinatesEqual
private void assertCoordinatesEqual(java.lang.String message, int dimension, float[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.
-
assertCoordinatesEqual
private void assertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, float[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.
-
assertCoordinatesEqual
private void assertCoordinatesEqual(java.lang.String message, int dimension, double[] expectedPts, int expectedOffset, double[] actualPts, int actualOffset, int numPoints, boolean strict, int reportedIndex)Implementation of public assertion methods with the addition of the coordinate index to be reported in error message.
-
formatComparaisonFailure
private static java.lang.String formatComparaisonFailure(java.lang.String message, int dimension, java.lang.Object expectedPts, int expectedOffset, java.lang.Object actualPts, int actualOffset, int failureIndex, java.lang.Number delta, int reportedIndex)Formats an error message for a comparison failure.- Parameters:
message- The header part of the message to format.dimension- The dimension of each coordinate points in the arrays.expectedPts- The array of expected coordinate values.expectedOffset- Index next to the point where the comparison failed.actualPts- The array of coordinate values to check against the expected ones.actualOffset- Index next to the point where the comparison failed.failureIndex- Zero-based index where the comparison failed.delta- The absolute delta between the expected and actual ordinate values.reportedIndex- Value to add to the coordinate index reported in the error message.
-
-