Class MockFeatureWithCalculationFixture
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
FieldsModifier and TypeFieldDescriptionstatic final ToDoubleFunction
<FeatureInputSingleObject> A default function for counting the number of pixels (voxels) in a single object. -
Method Summary
Modifier and TypeMethodDescriptionstatic Feature
<FeatureInputSingleObject> Creates a mock feature that counts the number of pixels in an object.static <T extends FeatureInput>
Feature<T> createMockFeatureWithCalculation
(ToDoubleFunction<T> funcCalculation) Creates a mock feature with a custom calculation function.static void
executeAndAssertCount
(int expectedCountCalc, int expectedCountExecute, CheckedRunnable<OperationFailedException> operation) Executes an operation and asserts the expected number of calls to internal methods.
-
Field Details
-
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'sexecute()
method match the expected counts.- Parameters:
expectedCountCalc
- the expected number of calls toFeature.calculate(org.anchoranalysis.feature.calculate.FeatureCalculationInput<T>)
expectedCountExecute
- the expected number of calls toexecute()
on the mock calculationoperation
- the operation to execute, typically involving the mock calculation- Throws:
OperationFailedException
- if the operation fails
-
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 aFeatureInputSingleObject
-
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 ofFeatureInput
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
-