use of org.kie.kogito.explainability.TestUtils.COUNTERFACTUAL_RESULT in project kogito-apps by kiegroup.
the class ExplanationServiceImplTest method testCounterfactualsExplainAsyncSuccess.
@SuppressWarnings("unchecked")
void testCounterfactualsExplainAsyncSuccess(ThrowingSupplier<BaseExplainabilityResult> invocation) {
when(instance.stream()).thenReturn(Stream.of(cfExplainerServiceHandlerMock));
when(cfExplainerMock.explainAsync(any(Prediction.class), eq(predictionProviderMock), any(Consumer.class))).thenReturn(CompletableFuture.completedFuture(COUNTERFACTUAL_RESULT));
BaseExplainabilityResult result = assertDoesNotThrow(invocation);
assertNotNull(result);
assertTrue(result instanceof CounterfactualExplainabilityResult);
CounterfactualExplainabilityResult counterfactualResult = (CounterfactualExplainabilityResult) result;
assertEquals(EXECUTION_ID, counterfactualResult.getExecutionId());
assertEquals(COUNTERFACTUAL_ID, counterfactualResult.getCounterfactualId());
assertSame(ExplainabilityStatus.SUCCEEDED, counterfactualResult.getStatus());
assertNull(counterfactualResult.getStatusDetails());
assertEquals(COUNTERFACTUAL_RESULT.getEntities().size(), counterfactualResult.getInputs().size());
assertEquals(COUNTERFACTUAL_RESULT.getOutput().size(), counterfactualResult.getOutputs().size());
assertTrue(counterfactualResult.getOutputs().stream().anyMatch(o -> o.getName().equals("output1")));
NamedTypedValue value = counterfactualResult.getOutputs().iterator().next();
assertTrue(value.getValue().isUnit());
assertEquals(Double.class.getSimpleName(), value.getValue().toUnit().getType());
assertEquals(555.0, value.getValue().toUnit().getValue().asDouble());
}
Aggregations