Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.dfa1.vortex.reader.array;

import io.github.dfa1.vortex.core.VortexException;
import org.junit.jupiter.api.Test;

import static io.github.dfa1.vortex.reader.array.TestArrays.bools;
import static io.github.dfa1.vortex.reader.array.TestArrays.bytes;
import static io.github.dfa1.vortex.reader.array.TestArrays.doubles;
import static io.github.dfa1.vortex.reader.array.TestArrays.ints;
import static io.github.dfa1.vortex.reader.array.TestArrays.longs;
import static io.github.dfa1.vortex.reader.array.TestArrays.shorts;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class DateTimePartsArraysTest {

@Test
void readLong_dispatchesEveryIntegerArrayType() {
// Given / When / Then — each narrow integer type widens to signed long
assertThat(DateTimePartsArrays.readLong(bytes((byte) -7), 0)).isEqualTo(-7L);
assertThat(DateTimePartsArrays.readLong(shorts((short) 300), 0)).isEqualTo(300L);
assertThat(DateTimePartsArrays.readLong(ints(70000), 0)).isEqualTo(70000L);
assertThat(DateTimePartsArrays.readLong(longs(5_000_000_000L), 0)).isEqualTo(5_000_000_000L);
}

@Test
void readLong_recursesThroughValidMaskedCell() {
// Given — a masked array whose cell is valid
MaskedArray masked = new MaskedArray(longs(42L, 43L), bools(true, true));

// When / Then — unwraps to the inner value
assertThat(DateTimePartsArrays.readLong(masked, 1)).isEqualTo(43L);
}

@Test
void readLong_nullMaskedCell_throws() {
// Given — a masked array whose cell is null
MaskedArray masked = new MaskedArray(longs(42L, 43L), bools(true, false));

// When / Then
assertThatThrownBy(() -> DateTimePartsArrays.readLong(masked, 1))
.isInstanceOf(VortexException.class)
.hasMessageContaining("null cell");
}

@Test
void readLong_unsupportedArrayType_throws() {
// Given — a DoubleArray is not a valid date-time part child
DoubleArray bad = doubles(1.0);

// When / Then
assertThatThrownBy(() -> DateTimePartsArrays.readLong(bad, 0))
.isInstanceOf(VortexException.class)
.hasMessageContaining("unsupported child array type");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,20 @@ void foldSumApplies() {
// Then
assertThat(sum).isEqualTo(36);
}

@Test
void materializeDecodesAllRows() {
// Given
LazyForIntArray sut = of(1000, 1, 2, 3);

// When
try (Arena arena = Arena.ofConfined()) {
MemorySegment seg = sut.materialize(arena);

// Then — materialized rows match the lazy getter
for (int i = 0; i < 3; i++) {
assertThat(seg.getAtIndex(LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.lang.foreign.ValueLayout;
import java.util.ArrayList;

import static io.github.dfa1.vortex.encoding.DTypes.BOOL;
import static io.github.dfa1.vortex.encoding.DTypes.F32;
import static io.github.dfa1.vortex.encoding.DTypes.F64;
import static io.github.dfa1.vortex.encoding.DTypes.I16;
Expand All @@ -16,6 +17,7 @@
import static io.github.dfa1.vortex.encoding.DTypes.I8;
import static io.github.dfa1.vortex.encoding.DTypes.U16;
import static io.github.dfa1.vortex.encoding.DTypes.U8;
import static io.github.dfa1.vortex.reader.array.TestArrays.bools;
import static io.github.dfa1.vortex.reader.array.TestArrays.bytes;
import static io.github.dfa1.vortex.reader.array.TestArrays.doubles;
import static io.github.dfa1.vortex.reader.array.TestArrays.floats;
Expand Down Expand Up @@ -211,6 +213,56 @@ void shortGetIntWidensUnsigned() {
// When / Then
assertThat(sut.getInt(0)).isEqualTo(65535);
}

@Test
void shortGetShortPatchFillAndNullPatches() {
// Given — fill 1, patches at 1->100, 3->200
ShortArray values = shorts((short) 100, (short) 200);
Array indices = ints(1, 3);
var sut = new LazySparseShortArray(I16, 5, (short) 1, 1, values, indices, 0L);

// When / Then — getShort hits both patch (p>=0) and fill (p<0)
assertThat(sut.getShort(0)).isEqualTo((short) 1);
assertThat(sut.getShort(1)).isEqualTo((short) 100);
assertThat(sut.getShort(3)).isEqualTo((short) 200);

// null patches → every position returns the fill (getShort, getInt and fold paths)
var nf = new LazySparseShortArray(I16, 3, (short) 7, 7, null, null, 0L);
assertThat(nf.getShort(0)).isEqualTo((short) 7);
assertThat(nf.getInt(0)).isEqualTo(7);
assertThat(nf.fold(0L, java.lang.Long::sum)).isEqualTo(21L);
}
}

@Nested
class Bool {

@Test
void getBooleanPatchAndFill() {
// Given — fill false, single patch true at index 2
BoolArray values = bools(true);
Array indices = ints(2);
var sut = new LazySparseBoolArray(BOOL, 4, false, values, indices, 0L);

// When / Then
assertThat(sut.getBoolean(0)).isFalse(); // fill (p<0)
assertThat(sut.getBoolean(2)).isTrue(); // patch
}

@Test
void forEachBooleanEmitsFillAndPatches() {
// Given
BoolArray values = bools(true);
Array indices = ints(2);
var sut = new LazySparseBoolArray(BOOL, 4, false, values, indices, 0L);

// When
var seen = new ArrayList<Boolean>();
sut.forEachBoolean(seen::add);

// Then
assertThat(seen).containsExactly(false, false, true, false);
}
}

@Nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,20 @@ void foldSumApplies() {
// Then
assertThat(sum).isZero();
}

@Test
void materializeDecodesAllRows() {
// Given
LazyZigZagIntArray sut = of(0, 1, 2, 3, 4);

// When
try (Arena arena = Arena.ofConfined()) {
MemorySegment seg = sut.materialize(arena);

// Then — materialized rows match the lazy getter
for (int i = 0; i < 5; i++) {
assertThat(seg.getAtIndex(LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
}
}
}
}