use of org.knime.core.data.v2.value.IntValueFactory in project knime-core by knime.
the class ValueFactoryUtilsTest method testAreEqual.
@Test
void testAreEqual() {
// both null
assertThat(ValueFactoryUtils.areEqual(null, null)).isTrue();
// first null
assertThat(ValueFactoryUtils.areEqual(null, IntValueFactory.INSTANCE)).isFalse();
// second null
assertThat(ValueFactoryUtils.areEqual(IntValueFactory.INSTANCE, null)).isFalse();
// same instance
assertThat(ValueFactoryUtils.areEqual(IntValueFactory.INSTANCE, IntValueFactory.INSTANCE)).isTrue();
// different types
assertThat(ValueFactoryUtils.areEqual(IntValueFactory.INSTANCE, DoubleValueFactory.INSTANCE)).isFalse();
// same type different instances
assertThat(ValueFactoryUtils.areEqual(IntValueFactory.INSTANCE, new IntValueFactory())).isTrue();
// dict encoded data cell value factory same type
assertThat(ValueFactoryUtils.areEqual(createDataCellValueFactory(), createDataCellValueFactory())).isTrue();
// dict encoded data cell value factory different type
assertThat(ValueFactoryUtils.areEqual(createDataCellValueFactory(), createDataCellValueFactory(PNGImageCellFactory.TYPE))).isFalse();
// legacy data cell value factory same type
assertThat(ValueFactoryUtils.areEqual(createLegacyDataCellValueFactory(XMLCell.TYPE), createLegacyDataCellValueFactory(XMLCell.TYPE))).isTrue();
// legacy dta cell value factory different type
assertThat(ValueFactoryUtils.areEqual(createLegacyDataCellValueFactory(XMLCell.TYPE), createLegacyDataCellValueFactory(PNGImageCellFactory.TYPE))).isFalse();
// collection same inner type
assertThat(ValueFactoryUtils.areEqual(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE))).isTrue();
// collection differing inner type
assertThat(ValueFactoryUtils.areEqual(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), createListValueFactory(DoubleValueFactory.INSTANCE, DoubleCell.TYPE))).isFalse();
// nested collections same inner type
assertThat(ValueFactoryUtils.areEqual(createListValueFactory(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), DataType.getType(ListCell.class, IntCell.TYPE)), createListValueFactory(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), DataType.getType(ListCell.class, IntCell.TYPE)))).isTrue();
// nested collections different inner type
assertThat(ValueFactoryUtils.areEqual(createListValueFactory(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), DataType.getType(ListCell.class, IntCell.TYPE)), createListValueFactory(createListValueFactory(DoubleValueFactory.INSTANCE, DoubleCell.TYPE), DataType.getType(ListCell.class, DoubleCell.TYPE)))).isFalse();
}
use of org.knime.core.data.v2.value.IntValueFactory in project knime-core by knime.
the class ValueFactoryUtilsTest method testGetTraitsOnCollectionValueFactory.
@Test
void testGetTraitsOnCollectionValueFactory() {
var valueFactory = new ListValueFactory();
valueFactory.initialize(new IntValueFactory(), IntCell.TYPE);
//
assertThat(ValueFactoryUtils.getTraits(valueFactory)).isInstanceOf(//
ListDataTraits.class).matches(//
this::hasLogicalTypeTrait).matches(this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).matches(//
this::hasLogicalTypeTrait).extracting(//
ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
// collection of data cell value factories
var listOfDataCells = createListValueFactory(createDataCellValueFactory(), XMLCell.TYPE);
//
assertThat(ValueFactoryUtils.getTraits(listOfDataCells)).isInstanceOf(//
ListDataTraits.class).matches(//
this::hasLogicalTypeTrait).matches(//
this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).extracting(//
ValueFactoryUtilsTest::extractLogicalTypeJson).matches(j -> j.get("value_factory_class").asText().equals(DictEncodedDataCellValueFactory.class.getName())).extracting(//
j -> j.get("data_type")).extracting(//
j -> j.get("cell_class").asText()).isEqualTo(XMLCell.class.getName());
// nested collection
var nestedCollection = createListValueFactory(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), DataType.getType(ListCell.class, IntCell.TYPE));
//
assertThat(ValueFactoryUtils.getTraits(nestedCollection)).isInstanceOf(//
ListDataTraits.class).matches(//
this::hasLogicalTypeTrait).matches(//
this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).matches(//
this::hasLogicalTypeTrait).matches(//
this::isListTypeTrait).extracting(//
ListDataTraits.class::cast).extracting(//
ListDataTraits::getInner).matches(//
this::hasLogicalTypeTrait).extracting(//
ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
// SparseListValueFactory (uses StructDataTraits)
var sparseList = new SparseListValueFactory();
sparseList.initialize(IntValueFactory.INSTANCE, IntCell.TYPE);
//
assertThat(ValueFactoryUtils.getTraits(sparseList)).isInstanceOf(//
StructDataTraits.class).extracting(//
StructDataTraits.class::cast).matches(//
this::hasLogicalTypeTrait).matches(//
t -> extractValueFactoryClassName(t).equals(SparseListValueFactory.class.getName())).extracting(//
t -> t.getDataTraits(0)).matches(//
this::hasLogicalTypeTrait).extracting(//
ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
}
Aggregations