Search in sources :

Example 21 with CounterfactualDomainRange

use of org.kie.kogito.explainability.api.CounterfactualDomainRange in project kogito-apps by kiegroup.

the class CounterfactualDomainSerialisationTest method testCounterfactualSearchDomain_Range_RoundTrip.

@Test
public void testCounterfactualSearchDomain_Range_RoundTrip() throws Exception {
    CounterfactualDomainRange domainRange = new CounterfactualDomainRange(new IntNode(18), new IntNode(65));
    CounterfactualSearchDomain searchDomain = new CounterfactualSearchDomain("age", new CounterfactualSearchDomainUnitValue("integer", "integer", Boolean.TRUE, domainRange));
    mapper.writeValue(writer, searchDomain);
    String searchDomainJson = writer.toString();
    assertNotNull(searchDomainJson);
    CounterfactualSearchDomain roundTrippedSearchDomain = mapper.readValue(searchDomainJson, CounterfactualSearchDomain.class);
    assertTrue(roundTrippedSearchDomain.getValue() instanceof CounterfactualSearchDomainUnitValue);
    assertEquals(searchDomain.getValue().getKind(), roundTrippedSearchDomain.getValue().getKind());
    assertEquals(searchDomain.getName(), roundTrippedSearchDomain.getName());
    assertEquals(searchDomain.getValue().getType(), roundTrippedSearchDomain.getValue().getType());
    assertEquals(searchDomain.getValue().toUnit().getBaseType(), roundTrippedSearchDomain.getValue().toUnit().getBaseType());
    assertEquals(searchDomain.getValue().toUnit().isFixed(), roundTrippedSearchDomain.getValue().toUnit().isFixed());
    assertTrue(roundTrippedSearchDomain.getValue().toUnit().getDomain() instanceof CounterfactualDomainRange);
    CounterfactualDomainRange roundTrippedDomainRange = (CounterfactualDomainRange) roundTrippedSearchDomain.getValue().toUnit().getDomain();
    assertEquals(domainRange.getLowerBound(), roundTrippedDomainRange.getLowerBound());
    assertEquals(domainRange.getUpperBound(), roundTrippedDomainRange.getUpperBound());
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) CounterfactualSearchDomainUnitValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test)

Aggregations

CounterfactualDomainRange (org.kie.kogito.explainability.api.CounterfactualDomainRange)21 Test (org.junit.jupiter.api.Test)18 CounterfactualSearchDomain (org.kie.kogito.explainability.api.CounterfactualSearchDomain)17 IntNode (com.fasterxml.jackson.databind.node.IntNode)13 CounterfactualExplainabilityRequest (org.kie.kogito.explainability.api.CounterfactualExplainabilityRequest)13 CounterfactualSearchDomainUnitValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainUnitValue)10 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)8 ArrayList (java.util.ArrayList)6 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)5 List (java.util.List)4 CounterfactualDomainCategorical (org.kie.kogito.explainability.api.CounterfactualDomainCategorical)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 TextNode (com.fasterxml.jackson.databind.node.TextNode)3 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)3 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 QuarkusTest (io.quarkus.test.junit.QuarkusTest)2 RequestLoggingFilter (io.restassured.filter.log.RequestLoggingFilter)2 ResponseLoggingFilter (io.restassured.filter.log.ResponseLoggingFilter)2 OffsetDateTime (java.time.OffsetDateTime)2