use of org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedCurrencyEntity 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());
}
Aggregations