Search in sources :

Example 1 with CurrencyEntity

use of org.kie.kogito.explainability.local.counterfactual.entities.CurrencyEntity in project kogito-apps by kiegroup.

the class CounterfactualEntityFactoryTest method testCurrencyFactory.

@Test
void testCurrencyFactory() {
    final Currency value = Currency.getInstance(Locale.ITALY);
    Feature feature = FeatureFactory.newCurrencyFeature("currrency-feature", value);
    CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof FixedCurrencyEntity);
    assertEquals(Type.CURRENCY, counterfactualEntity.asFeature().getType());
    final Feature fixedFeature = FeatureFactory.newCurrencyFeature("currrency-feature", value);
    FeatureDomain domain = CurrencyFeatureDomain.create(Currency.getAvailableCurrencies());
    feature = FeatureFactory.newCurrencyFeature("currrency-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof CurrencyEntity);
    assertEquals(domain.getCategories(), ((CurrencyEntity) counterfactualEntity).getValueRange());
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
    domain = CurrencyFeatureDomain.create(new ArrayList<>(Currency.getAvailableCurrencies()));
    feature = FeatureFactory.newCurrencyFeature("currrency-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof CurrencyEntity);
    assertEquals(domain.getCategories(), ((CurrencyEntity) counterfactualEntity).getValueRange());
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
    Currency[] currencies = List.of(Locale.ITALY, Locale.UK, Locale.US).stream().map(Currency::getInstance).collect(Collectors.toList()).toArray(new Currency[0]);
    domain = CurrencyFeatureDomain.create(currencies);
    feature = FeatureFactory.newCurrencyFeature("currrency-feature", value, domain);
    counterfactualEntity = CounterfactualEntityFactory.from(feature);
    assertTrue(counterfactualEntity instanceof CurrencyEntity);
    assertEquals(currencies.length, ((CurrencyEntity) counterfactualEntity).getValueRange().size());
    assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
}
Also used : CounterfactualEntity(org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity) FixedCurrencyEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCurrencyEntity) Currency(java.util.Currency) ArrayList(java.util.ArrayList) ObjectFeatureDomain(org.kie.kogito.explainability.model.domain.ObjectFeatureDomain) EmptyFeatureDomain(org.kie.kogito.explainability.model.domain.EmptyFeatureDomain) CategoricalFeatureDomain(org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain) CurrencyFeatureDomain(org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain) URIFeatureDomain(org.kie.kogito.explainability.model.domain.URIFeatureDomain) DurationFeatureDomain(org.kie.kogito.explainability.model.domain.DurationFeatureDomain) TimeFeatureDomain(org.kie.kogito.explainability.model.domain.TimeFeatureDomain) NumericalFeatureDomain(org.kie.kogito.explainability.model.domain.NumericalFeatureDomain) BinaryFeatureDomain(org.kie.kogito.explainability.model.domain.BinaryFeatureDomain) FeatureDomain(org.kie.kogito.explainability.model.domain.FeatureDomain) Feature(org.kie.kogito.explainability.model.Feature) FixedCurrencyEntity(org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCurrencyEntity) CurrencyEntity(org.kie.kogito.explainability.local.counterfactual.entities.CurrencyEntity) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Currency (java.util.Currency)1 Test (org.junit.jupiter.api.Test)1 CounterfactualEntity (org.kie.kogito.explainability.local.counterfactual.entities.CounterfactualEntity)1 CurrencyEntity (org.kie.kogito.explainability.local.counterfactual.entities.CurrencyEntity)1 FixedCurrencyEntity (org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCurrencyEntity)1 Feature (org.kie.kogito.explainability.model.Feature)1 BinaryFeatureDomain (org.kie.kogito.explainability.model.domain.BinaryFeatureDomain)1 CategoricalFeatureDomain (org.kie.kogito.explainability.model.domain.CategoricalFeatureDomain)1 CurrencyFeatureDomain (org.kie.kogito.explainability.model.domain.CurrencyFeatureDomain)1 DurationFeatureDomain (org.kie.kogito.explainability.model.domain.DurationFeatureDomain)1 EmptyFeatureDomain (org.kie.kogito.explainability.model.domain.EmptyFeatureDomain)1 FeatureDomain (org.kie.kogito.explainability.model.domain.FeatureDomain)1 NumericalFeatureDomain (org.kie.kogito.explainability.model.domain.NumericalFeatureDomain)1 ObjectFeatureDomain (org.kie.kogito.explainability.model.domain.ObjectFeatureDomain)1 TimeFeatureDomain (org.kie.kogito.explainability.model.domain.TimeFeatureDomain)1 URIFeatureDomain (org.kie.kogito.explainability.model.domain.URIFeatureDomain)1