Class MockFeatureWithCalculationFixture

Object
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 Details

    • DEFAULT_FUNC_NUM_PIXELS

      public static final ToDoubleFunction<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, CheckedRunnable<OperationFailedException> operation) throws 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:
      OperationFailedException - if the operation fails
    • createMockFeatureWithCalculation

      public static Feature<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 FeatureInput> 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