use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class PrettyPrinterTest method shouldHandleNestedLists.
@Test
void shouldHandleNestedLists() {
// Given
PrettyPrinter printer = new PrettyPrinter();
ListValue list = list(intValue(1), list(intValue(2), intValue(3)), intValue(4));
// When
list.writeTo(printer);
// Then
assertThat(printer.value()).isEqualTo("[1, [2, 3], 4]");
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class AnyValueComparatorTest method shouldTernaryCompareLists.
@Test
void shouldTernaryCompareLists() {
assertTernaryCompare(EMPTY_LIST, EMPTY_LIST, EQUAL);
assertTernaryCompare(EMPTY_LIST, Values.EMPTY_BYTE_ARRAY, EQUAL);
assertTernaryCompare(EMPTY_LIST, NO_VALUE, UNDEFINED);
assertTernaryCompare(EMPTY_LIST, list("foo"), SMALLER_THAN);
assertTernaryCompare(EMPTY_LIST, stringArray("foo"), SMALLER_THAN);
assertTernaryCompare(list("foo"), stringArray("foo"), EQUAL);
assertTernaryCompare(list(stringArray("foo")), list(stringArray("foo")), EQUAL);
assertTernaryCompare(list(list("foo")), list(list("foo")), EQUAL);
assertTernaryCompare(list(stringValue("foo")), intValue(42), UNDEFINED);
assertTernaryCompare(list(stringValue("foo")), list(intValue(42)), UNDEFINED);
ListValue listReference = list(stringValue("foo"), NO_VALUE, intValue(42));
assertTernaryCompare(listReference, list(stringValue("foo"), NO_VALUE, intValue(42)), UNDEFINED);
// make sure we don't do reference equal check
assertTernaryCompare(listReference, listReference, UNDEFINED);
assertTernaryCompare(list(stringValue("foo")), list(stringValue("foo"), intValue(42), NO_VALUE), SMALLER_THAN);
assertTernaryCompare(list(stringValue("foo"), intValue(42), NO_VALUE), list(stringValue("foo")), GREATER_THAN);
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class TernaryEqualityTest method shouldCompareListsAndArrays.
@Test
void shouldCompareListsAndArrays() {
ListValue list = list(intValue(1), intValue(2), intValue(3));
// Equals
assertTernaryEquality(list, byteArray(new byte[] { 1, 2, 3 }), Equality.TRUE);
assertTernaryEquality(list, shortArray(new short[] { 1, 2, 3 }), Equality.TRUE);
assertTernaryEquality(list, intArray(new int[] { 1, 2, 3 }), Equality.TRUE);
assertTernaryEquality(list, longArray(new long[] { 1, 2, 3 }), Equality.TRUE);
assertTernaryEquality(list, floatArray(new float[] { 1, 2, 3 }), Equality.TRUE);
assertTernaryEquality(list, doubleArray(new double[] { 1, 2, 3 }), Equality.TRUE);
assertTernaryEquality(list(intArray(new int[] { 1, 2, 3 })), list(list), Equality.TRUE);
// Not equals
assertTernaryEquality(list, byteArray(new byte[] { 11, 2, 3 }), Equality.FALSE);
assertTernaryEquality(list, shortArray(new short[] { 11, 2, 3 }), Equality.FALSE);
assertTernaryEquality(list, intArray(new int[] { 11, 2, 3 }), Equality.FALSE);
assertTernaryEquality(list, longArray(new long[] { 11, 2, 3 }), Equality.FALSE);
assertTernaryEquality(list, floatArray(new float[] { 11, 2, 3 }), Equality.FALSE);
assertTernaryEquality(list, doubleArray(new double[] { 11, 2, 3 }), Equality.FALSE);
assertTernaryEquality(list(intArray(new int[] { 11, 2, 3 })), list(list), Equality.FALSE);
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class TernaryEqualityTest method shouldHandleListsWithNoValue.
@Test
void shouldHandleListsWithNoValue() {
ListValue listWithNoValue = list(intValue(1), NO_VALUE, intValue(2));
assertTernaryEquality(listWithNoValue, list(intValue(1), intValue(2), intValue(3), intValue(4)), Equality.FALSE);
assertTernaryEquality(listWithNoValue, list(intValue(1), NO_VALUE), Equality.FALSE);
assertTernaryEquality(listWithNoValue, list(intValue(2), NO_VALUE, intValue(2)), Equality.FALSE);
assertTernaryEquality(listWithNoValue, list(intValue(1), NO_VALUE, intValue(3)), Equality.FALSE);
// check so that we are not using a referential equality check
assertTernaryEquality(listWithNoValue, listWithNoValue, Equality.UNDEFINED);
assertTernaryEquality(listWithNoValue, list(intValue(1), NO_VALUE, intValue(2)), Equality.UNDEFINED);
assertTernaryEquality(listWithNoValue, list(intValue(2), NO_VALUE, intValue(2)), Equality.FALSE);
assertTernaryEquality(list(NO_VALUE, NO_VALUE, NO_VALUE), list(NO_VALUE, NO_VALUE), Equality.FALSE);
assertTernaryEquality(list(intValue(1), intValue(2)), list(intValue(1), stringValue("two")), Equality.FALSE);
}
use of org.neo4j.values.virtual.ListValue in project neo4j by neo4j.
the class HeapTrackingListValueBuilderTest method addAndIterateElements.
@Test
void addAndIterateElements() {
int iterations = rnd.nextInt(10, 1000);
for (int i = 0; i < iterations; i++) {
listValueBuilder.add(Values.longValue(i));
}
// Validate builder size
long memoryTrackerActualSize = meter.measureDeep(memoryTracker);
long actualBuilderSize = meter.measureDeep(listValueBuilder) - memoryTrackerActualSize;
long estimatedBuilderSize = memoryTracker.estimatedHeapMemory();
assertEquals(actualBuilderSize, estimatedBuilderSize);
// Validate value size
ListValue listValue = listValueBuilder.build();
long actualValueSize = meter.measureDeep(listValue) - memoryTrackerActualSize;
long estimatedValueSize = listValue.estimatedHeapUsage();
assertEquals(actualValueSize, estimatedValueSize);
// Validate items
Iterator<AnyValue> iterator = listValue.iterator();
for (int i = 0; i < iterations; i++) {
assertTrue(iterator.hasNext());
assertEquals(i, ((LongValue) iterator.next()).longValue());
}
assertFalse(iterator.hasNext());
}
Aggregations