Search in sources :

Example 16 with ListValue

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]");
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Test(org.junit.jupiter.api.Test)

Example 17 with ListValue

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);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Test(org.junit.jupiter.api.Test)

Example 18 with ListValue

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);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Test(org.junit.jupiter.api.Test)

Example 19 with ListValue

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);
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) Test(org.junit.jupiter.api.Test)

Example 20 with ListValue

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());
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) Test(org.junit.jupiter.api.Test)

Aggregations

ListValue (org.neo4j.values.virtual.ListValue)28 Test (org.junit.jupiter.api.Test)19 AnyValue (org.neo4j.values.AnyValue)14 ArrayList (java.util.ArrayList)3 LongValue (org.neo4j.values.storable.LongValue)3 ProcedureException (org.neo4j.internal.kernel.api.exceptions.ProcedureException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 KernelIntegrationTest (org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)2 CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)2 BooleanValue (org.neo4j.values.storable.BooleanValue)2 Value (org.neo4j.values.storable.Value)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)2 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 SchemaWrite (org.neo4j.internal.kernel.api.SchemaWrite)1 EmptyMemoryTracker (org.neo4j.memory.EmptyMemoryTracker)1 MemoryTracker (org.neo4j.memory.MemoryTracker)1