use of org.kie.kogito.explainability.local.counterfactual.entities.fixed.FixedBinaryEntity in project kogito-apps by kiegroup.
the class CounterfactualEntityFactoryTest method testBinaryFactory.
@Test
void testBinaryFactory() {
final ByteBuffer value = ByteBuffer.allocate(256);
Feature feature = FeatureFactory.newBinaryFeature("binary-feature", value);
CounterfactualEntity counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertTrue(counterfactualEntity instanceof FixedBinaryEntity);
assertEquals(Type.BINARY, counterfactualEntity.asFeature().getType());
final List<ByteBuffer> categories = Stream.of("bar".getBytes(), "baz".getBytes(), "fun".getBytes()).map(ByteBuffer::wrap).collect(Collectors.toList());
FeatureDomain domain = BinaryFeatureDomain.create(categories);
feature = FeatureFactory.newBinaryFeature("binary-feature", value, domain);
counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertTrue(counterfactualEntity instanceof BinaryEntity);
assertEquals(domain.getCategories(), ((BinaryEntity) counterfactualEntity).getValueRange());
domain = BinaryFeatureDomain.create(new HashSet<>(categories));
feature = FeatureFactory.newBinaryFeature("binary-feature", value, domain);
counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertEquals(domain.getCategories(), ((BinaryEntity) counterfactualEntity).getValueRange());
domain = BinaryFeatureDomain.create(ByteBuffer.wrap("bar".getBytes()), ByteBuffer.wrap("baz".getBytes()), ByteBuffer.wrap("fun".getBytes()));
feature = FeatureFactory.newBinaryFeature("binary-feature", value, domain);
counterfactualEntity = CounterfactualEntityFactory.from(feature);
assertEquals(domain.getCategories(), ((BinaryEntity) counterfactualEntity).getValueRange());
assertEquals(value, counterfactualEntity.asFeature().getValue().getUnderlyingObject());
}
Aggregations