Class TransformTestCase
MathTransform
implementations. Subclasses shall assign a value
to the transform
field before to invoke any method in this class. The assigned
transform must support the MathTransform.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 some
is<
Operation>Supported
fields to false
.
Once the fields are assigned their values, subclasses can invoke any of the verify
methods 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
FieldsModifier and TypeFieldDescriptionprotected boolean
true
ifMathTransform.transform(double[],int,double[],int,int)
is supported.protected boolean
true
ifMathTransform.transform(double[],int,float[],int,int)
is supported.protected boolean
true
ifMathTransform.transform(float[],int,double[],int,int)
is supported.protected boolean
true
ifMathTransform.transform(float[],int,float[],int,int)
is supported.protected boolean
true
ifMathTransform.inverse()
is supported.protected boolean
true
if the destination array can be the same than the source array, and the source and target region of the array can overlap.private static final int
The maximal offset (in number of coordinate points), exclusive, to apply when testingMathTransform.transform(...)
with overlapping arrays.protected double
Maximum difference to be accepted when comparing a transformed ordinate value with the expected one.protected MathTransform
The transform being tested. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a test case initialized to default values. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Ensures that allis<
Operation>Supported
fields are set totrue
.protected final void
assertCoordinateEquals
(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 final void
assertCoordinateEquals
(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 final void
assertCoordinateEquals
(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 final void
assertCoordinateEquals
(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 final void
assertCoordinatesEqual
(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 void
assertCoordinatesEqual
(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 final void
assertCoordinatesEqual
(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 void
assertCoordinatesEqual
(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 final void
assertCoordinatesEqual
(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 void
assertCoordinatesEqual
(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 final void
assertCoordinatesEqual
(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 void
assertCoordinatesEqual
(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 String
formatComparaisonFailure
(String message, int dimension, Object expectedPts, int expectedOffset, Object actualPts, int actualOffset, int failureIndex, Number delta, int reportedIndex) Formats an error message for a comparison failure.protected double
tolerance
(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 void
verifyInverse
(double[] coordinates) Transforms the given coordinates, applies the inverse transform and compares with the original values.protected void
verifyInverse
(float[] coordinates) Transforms the given coordinates, applies the inverse transform and compares with the original values.protected void
verifyTransform
(double[] coordinates, double[] expected) Transforms the given coordinates and verifies that the result is equals (within a positive delta) to the expected ones.
-
Field Details
-
POINTS_OFFSET
private static final int POINTS_OFFSETThe 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:
-
transform
The transform being tested. Subclasses should assign a value to this field, typically in some method annotated with JUnitBefore
annotation.Subclasses should consider setting a tolerance threshold value together with the transform.
- See Also:
-
isDoubleToDoubleSupported
protected boolean isDoubleToDoubleSupportedtrue
ifMathTransform.transform(double[],int,double[],int,int)
is supported. The default value istrue
. Vendor can set this value tofalse
in order to test a transform which is not fully implemented. -
isFloatToFloatSupported
protected boolean isFloatToFloatSupportedtrue
ifMathTransform.transform(float[],int,float[],int,int)
is supported. The default value istrue
. Vendor can set this value tofalse
in order to test a transform which is not fully implemented. -
isDoubleToFloatSupported
protected boolean isDoubleToFloatSupportedtrue
ifMathTransform.transform(double[],int,float[],int,int)
is supported. The default value istrue
. Vendor can set this value tofalse
in order to test a transform which is not fully implemented. -
isFloatToDoubleSupported
protected boolean isFloatToDoubleSupportedtrue
ifMathTransform.transform(float[],int,double[],int,int)
is supported. The default value istrue
. Vendor can set this value tofalse
in order to test a transform which is not fully implemented. -
isOverlappingArraySupported
protected boolean isOverlappingArraySupportedtrue
if 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 tofalse
in order to test a transform which is not fully implemented. -
isInverseTransformSupported
protected boolean isInverseTransformSupportedtrue
ifMathTransform.inverse()
is supported. -
tolerance
protected double toleranceMaximum 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:
-
-
Constructor Details
-
TransformTestCase
protected TransformTestCase()
-
-
Method Details
-
tolerance
protected double tolerance(double ordinate) Returns the tolerance threshold for comparing the given ordinate value. The default implementation returns thetolerance
value 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>Supported
fields are set totrue
. This method can be invoked before testing a math transform which is expected to be fully implemented. -
verifyTransform
Transforms 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
isInverseTransformSupported
istrue
, 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, ornull
ifcoordinates
is expected to be null.- Throws:
TransformException
- if the transformation failed.
-
verifyInverse
Transforms 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
Transforms 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
Transforms 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
float
values instead thandouble
for making sure that theMathTransform.transform(float[], ...)
andMathTransform.transform(double[], ...)
methods produces the same numerical values. Thedouble
values 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 offloat
values.- Returns:
- The transformed coordinates, returned for convenience.
- Throws:
TransformException
- if at least one coordinate can't be transformed.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(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
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(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
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(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
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinateEquals
protected final void assertCoordinateEquals(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
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(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 theexpectedPts
array.actualPts
- The array of coordinate values to check against the expected ones.actualOffset
- Index of the first valid ordinate in theactualPts
array.numPoints
- Number of coordinate points to compare.strict
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(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 theexpectedPts
array.actualPts
- The array of coordinate values to check against the expected ones.actualOffset
- Index of the first valid ordinate in theactualPts
array.numPoints
- Number of coordinate points to compare.strict
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(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 theexpectedPts
array.actualPts
- The array of coordinate values to check against the expected ones.actualOffset
- Index of the first valid ordinate in theactualPts
array.numPoints
- Number of coordinate points to compare.strict
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
protected final void assertCoordinatesEqual(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 theexpectedPts
array.actualPts
- The array of coordinate values to check against the expected ones.actualOffset
- Index of the first valid ordinate in theactualPts
array.numPoints
- Number of coordinate points to compare.strict
-true
for ignoring the tolerance threshold. In such case, ordinate values are checked for strict equality.
-
assertCoordinatesEqual
private void assertCoordinatesEqual(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(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(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(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 String formatComparaisonFailure(String message, int dimension, Object expectedPts, int expectedOffset, Object actualPts, int actualOffset, int failureIndex, 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.
-