Class MockFeatureWithCalculationFixture

Object
org.anchoranalysis.test.feature.plugins.mockfeature.MockFeatureWithCalculationFixture

public class MockFeatureWithCalculationFixture
extends Object
Creates a mock-feature which used a mock CalculationPart under the hood

Tests can be executed so as to count the number of times the calculation and feature's MockFeatureWithCalculation.calculate(org.anchoranalysis.feature.calculate.FeatureCalculationInput<org.anchoranalysis.feature.input.FeatureInput>) method are called.

This is implemented using (ugly) static methods and some reflection, as Feature's must remain valid Anchor-bean's and thus cannot be inner-classes or rely on parameterization in the constructor.

Author:
Owen Feehan
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static ToDoubleFunction<org.anchoranalysis.image.feature.input.FeatureInputSingleObject> DEFAULT_FUNC_NUM_PIXELS
    A default function for counting the number of pixels (voxels) in a single object.
  • Method Summary

    Modifier and Type Method Description
    static org.anchoranalysis.feature.bean.Feature<org.anchoranalysis.image.feature.input.FeatureInputSingleObject> createMockFeatureWithCalculation()
    Creates a mock feature that counts the number of pixels in an object.
    static <T extends org.anchoranalysis.feature.input.FeatureInput>
    org.anchoranalysis.feature.bean.Feature<T>
    createMockFeatureWithCalculation​(ToDoubleFunction<T> funcCalculation)
    Creates a mock feature with a custom calculation function.
    static void executeAndAssertCount​(int expectedCountCalc, int expectedCountExecute, org.anchoranalysis.core.functional.checked.CheckedRunnable<org.anchoranalysis.core.exception.OperationFailedException> operation)
    Executes an operation and asserts the expected number of calls to internal methods.

    Methods inherited from class java.lang.Object

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

    • DEFAULT_FUNC_NUM_PIXELS

      public static final ToDoubleFunction<org.anchoranalysis.image.feature.input.FeatureInputSingleObject> DEFAULT_FUNC_NUM_PIXELS
      A default function for counting the number of pixels (voxels) in a single object.

      This function takes a FeatureInputSingleObject as input and returns the number of "on" voxels in the object as a double value. It is used as the default calculation function when creating a mock feature without specifying a custom function.

  • Method Details

    • executeAndAssertCount

      public static void executeAndAssertCount​(int expectedCountCalc, int expectedCountExecute, org.anchoranalysis.core.functional.checked.CheckedRunnable<org.anchoranalysis.core.exception.OperationFailedException> operation) throws org.anchoranalysis.core.exception.OperationFailedException
      Executes an operation and asserts the expected number of calls to internal methods.

      This method runs the given operation and then checks if the number of calls to Feature.calculate(org.anchoranalysis.feature.calculate.FeatureCalculationInput<T>) and the mock calculation's execute() method match the expected counts.

      Parameters:
      expectedCountCalc - the expected number of calls to Feature.calculate(org.anchoranalysis.feature.calculate.FeatureCalculationInput<T>)
      expectedCountExecute - the expected number of calls to execute() on the mock calculation
      operation - the operation to execute, typically involving the mock calculation
      Throws:
      org.anchoranalysis.core.exception.OperationFailedException - if the operation fails
    • createMockFeatureWithCalculation

      public static org.anchoranalysis.feature.bean.Feature<org.anchoranalysis.image.feature.input.FeatureInputSingleObject> createMockFeatureWithCalculation()
      Creates a mock feature that counts the number of pixels in an object.

      This mock feature uses a mock CalculationPart under the hood to perform the pixel counting.

      Returns:
      a new Feature that counts pixels in a FeatureInputSingleObject
    • createMockFeatureWithCalculation

      public static <T extends org.anchoranalysis.feature.input.FeatureInput> org.anchoranalysis.feature.bean.Feature<T> createMockFeatureWithCalculation​(ToDoubleFunction<T> funcCalculation)
      Creates a mock feature with a custom calculation function.

      This method creates a mock feature that uses the provided function to calculate its result. It uses a mock CalculationPart under the hood.

      Type Parameters:
      T - the type of FeatureInput for the feature
      Parameters:
      funcCalculation - a function that calculates the result for the mock feature
      Returns:
      a new Feature that uses the provided calculation function