use of org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedDurationEntity in project kogito-apps by kiegroup.
the class CounterfactualEntityFactoryTest method testDurationFactory.
@Test
void testDurationFactory() {
final Duration value = Duration.ofDays(1);
Feature feature = FeatureFactory.newDurationFeature("duration-feature", value);
CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertTrue(counterfactualEntity instanceof FixedDurationEntity);
assertEquals(Type.DURATION, counterfactualEntity.asFeature().getType());
FeatureDomain domain = DurationFeatureDomain.create(0, 60, ChronoUnit.SECONDS);
feature = FeatureFactory.newDurationFeature("duration-feature", value, domain);
counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertTrue(counterfactualEntity instanceof DurationEntity);
assertEquals(Type.DURATION, counterfactualEntity.asFeature().getType());
assertFalse(counterfactualEntity.isConstrained());
CounterfactualEntity entity = DurationEntity.from(feature, Duration.ZERO, Duration.ofDays(2));
assertEquals(0, entity.distance());
assertTrue(((DurationEntity) entity).getValueRange().contains(1e5));
assertFalse(((DurationEntity) entity).getValueRange().contains(2e5));
assertFalse(entity.isConstrained());
entity = DurationEntity.from(feature, Duration.ZERO, Duration.ofDays(2), false);
assertEquals(0, entity.distance());
assertFalse(entity.isConstrained());
FeatureDistribution distribution = new NumericFeatureDistribution(feature, new Random().doubles(10).toArray());
entity = DurationEntity.from(feature, Duration.ZERO, Duration.ofDays(2), distribution);
assertEquals(0, entity.distance());
assertFalse(entity.isConstrained());
}
Aggregations