Class TransformTestCase

java.lang.Object
org.opengis.test.TestCase
org.opengis.test.referencing.TransformTestCase

public abstract class TransformTestCase extends TestCase
Base class for tests of 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

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    protected boolean
    protected boolean
    protected boolean
    protected boolean
    true if MathTransform.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 testing MathTransform.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

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a test case initialized to default values.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Ensures that all is<Operation>Supported fields are set to true.
    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 of MathTransform.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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • POINTS_OFFSET

      private static final int POINTS_OFFSET
      The maximal offset (in number of coordinate points), exclusive, to apply when testing MathTransform.transform(...) with overlapping arrays. Higher values make the tests more extensive but slower. Small values like 8 are usually enough.
      See Also:
    • transform

      protected MathTransform transform
      The transform being tested. Subclasses should assign a value to this field, typically in some method annotated with JUnit Before annotation.

      Subclasses should consider setting a tolerance threshold value together with the transform.

      See Also:
    • isDoubleToDoubleSupported

      protected boolean isDoubleToDoubleSupported
      true if MathTransform.transform(double[],int,double[],int,int) is supported. The default value is true. Vendor can set this value to false in order to test a transform which is not fully implemented.
    • isFloatToFloatSupported

      protected boolean isFloatToFloatSupported
      true if MathTransform.transform(float[],int,float[],int,int) is supported. The default value is true. Vendor can set this value to false in order to test a transform which is not fully implemented.
    • isDoubleToFloatSupported

      protected boolean isDoubleToFloatSupported
      true if MathTransform.transform(double[],int,float[],int,int) is supported. The default value is true. Vendor can set this value to false in order to test a transform which is not fully implemented.
    • isFloatToDoubleSupported

      protected boolean isFloatToDoubleSupported
      true if MathTransform.transform(float[],int,double[],int,int) is supported. The default value is true. Vendor can set this value to false in order to test a transform which is not fully implemented.
    • isOverlappingArraySupported

      protected boolean isOverlappingArraySupported
      true 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 is true. Vendor can set this value to false in order to test a transform which is not fully implemented.
    • isInverseTransformSupported

      protected boolean isInverseTransformSupported
      true if MathTransform.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 the tolerance(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()
      Creates a test case initialized to default values. The transform is initially null, the tolerance threshold is initially zero and all is<Operation>Supported are set to true.
  • Method Details

    • tolerance

      protected double tolerance(double ordinate)
      Returns the tolerance threshold for comparing the given ordinate value. The default implementation returns the tolerance 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 all is<Operation>Supported fields are set to true. 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 TransformException
      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 is true, 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, or null if coordinates is expected to be null.
      Throws:
      TransformException - if the transformation failed.
    • verifyInverse

      protected void verifyInverse(double[] coordinates) throws TransformException
      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

      protected void verifyInverse(float[] coordinates) throws TransformException
      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

      protected float[] verifyConsistency(float[] sourceFloats) throws TransformException
      Transforms coordinates using various versions of MathTransform.transform(...) and verifies that they produce the same numerical values. The values calculated by MathTransform.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 than double for making sure that the MathTransform.transform(float[], ...) and MathTransform.transform(double[], ...) methods produces the same numerical values. The double 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 of float 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 the expectedPts array.
      actualPts - The array of coordinate values to check against the expected ones.
      actualOffset - Index of the first valid ordinate in the actualPts 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 the expectedPts array.
      actualPts - The array of coordinate values to check against the expected ones.
      actualOffset - Index of the first valid ordinate in the actualPts 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 the expectedPts array.
      actualPts - The array of coordinate values to check against the expected ones.
      actualOffset - Index of the first valid ordinate in the actualPts 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 the expectedPts array.
      actualPts - The array of coordinate values to check against the expected ones.
      actualOffset - Index of the first valid ordinate in the actualPts 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.