Skip to content

Commit b077089

Browse files
dfa1claude
andcommitted
test(reader): cover For/ZigZag Int materialize, Sparse Short/Bool, DateTimePartsArrays
- LazyForIntArray / LazyZigZagIntArray: add the missing materialize() bulk-decode - LazySparseShortArray: getShort patch/fill/null + getInt/fold null-patches path - LazySparseBoolArray: getBoolean patch/fill + forEachBoolean (was untested) - DateTimePartsArrays: new test covering readLong for every integer type, masked valid/null cells, and the unsupported-type default All five at 100% line + branch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0f938eb commit b077089

4 files changed

Lines changed: 140 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package io.github.dfa1.vortex.reader.array;
2+
3+
import io.github.dfa1.vortex.core.VortexException;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static io.github.dfa1.vortex.reader.array.TestArrays.bools;
7+
import static io.github.dfa1.vortex.reader.array.TestArrays.bytes;
8+
import static io.github.dfa1.vortex.reader.array.TestArrays.doubles;
9+
import static io.github.dfa1.vortex.reader.array.TestArrays.ints;
10+
import static io.github.dfa1.vortex.reader.array.TestArrays.longs;
11+
import static io.github.dfa1.vortex.reader.array.TestArrays.shorts;
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
14+
15+
class DateTimePartsArraysTest {
16+
17+
@Test
18+
void readLong_dispatchesEveryIntegerArrayType() {
19+
// Given / When / Then — each narrow integer type widens to signed long
20+
assertThat(DateTimePartsArrays.readLong(bytes((byte) -7), 0)).isEqualTo(-7L);
21+
assertThat(DateTimePartsArrays.readLong(shorts((short) 300), 0)).isEqualTo(300L);
22+
assertThat(DateTimePartsArrays.readLong(ints(70000), 0)).isEqualTo(70000L);
23+
assertThat(DateTimePartsArrays.readLong(longs(5_000_000_000L), 0)).isEqualTo(5_000_000_000L);
24+
}
25+
26+
@Test
27+
void readLong_recursesThroughValidMaskedCell() {
28+
// Given — a masked array whose cell is valid
29+
MaskedArray masked = new MaskedArray(longs(42L, 43L), bools(true, true));
30+
31+
// When / Then — unwraps to the inner value
32+
assertThat(DateTimePartsArrays.readLong(masked, 1)).isEqualTo(43L);
33+
}
34+
35+
@Test
36+
void readLong_nullMaskedCell_throws() {
37+
// Given — a masked array whose cell is null
38+
MaskedArray masked = new MaskedArray(longs(42L, 43L), bools(true, false));
39+
40+
// When / Then
41+
assertThatThrownBy(() -> DateTimePartsArrays.readLong(masked, 1))
42+
.isInstanceOf(VortexException.class)
43+
.hasMessageContaining("null cell");
44+
}
45+
46+
@Test
47+
void readLong_unsupportedArrayType_throws() {
48+
// Given — a DoubleArray is not a valid date-time part child
49+
DoubleArray bad = doubles(1.0);
50+
51+
// When / Then
52+
assertThatThrownBy(() -> DateTimePartsArrays.readLong(bad, 0))
53+
.isInstanceOf(VortexException.class)
54+
.hasMessageContaining("unsupported child array type");
55+
}
56+
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyForIntArrayTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,20 @@ void foldSumApplies() {
6363
// Then
6464
assertThat(sum).isEqualTo(36);
6565
}
66+
67+
@Test
68+
void materializeDecodesAllRows() {
69+
// Given
70+
LazyForIntArray sut = of(1000, 1, 2, 3);
71+
72+
// When
73+
try (Arena arena = Arena.ofConfined()) {
74+
MemorySegment seg = sut.materialize(arena);
75+
76+
// Then — materialized rows match the lazy getter
77+
for (int i = 0; i < 3; i++) {
78+
assertThat(seg.getAtIndex(LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
79+
}
80+
}
81+
}
6682
}

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazySparseArrayTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.lang.foreign.ValueLayout;
99
import java.util.ArrayList;
1010

11+
import static io.github.dfa1.vortex.encoding.DTypes.BOOL;
1112
import static io.github.dfa1.vortex.encoding.DTypes.F32;
1213
import static io.github.dfa1.vortex.encoding.DTypes.F64;
1314
import static io.github.dfa1.vortex.encoding.DTypes.I16;
@@ -16,6 +17,7 @@
1617
import static io.github.dfa1.vortex.encoding.DTypes.I8;
1718
import static io.github.dfa1.vortex.encoding.DTypes.U16;
1819
import static io.github.dfa1.vortex.encoding.DTypes.U8;
20+
import static io.github.dfa1.vortex.reader.array.TestArrays.bools;
1921
import static io.github.dfa1.vortex.reader.array.TestArrays.bytes;
2022
import static io.github.dfa1.vortex.reader.array.TestArrays.doubles;
2123
import static io.github.dfa1.vortex.reader.array.TestArrays.floats;
@@ -211,6 +213,56 @@ void shortGetIntWidensUnsigned() {
211213
// When / Then
212214
assertThat(sut.getInt(0)).isEqualTo(65535);
213215
}
216+
217+
@Test
218+
void shortGetShortPatchFillAndNullPatches() {
219+
// Given — fill 1, patches at 1->100, 3->200
220+
ShortArray values = shorts((short) 100, (short) 200);
221+
Array indices = ints(1, 3);
222+
var sut = new LazySparseShortArray(I16, 5, (short) 1, 1, values, indices, 0L);
223+
224+
// When / Then — getShort hits both patch (p>=0) and fill (p<0)
225+
assertThat(sut.getShort(0)).isEqualTo((short) 1);
226+
assertThat(sut.getShort(1)).isEqualTo((short) 100);
227+
assertThat(sut.getShort(3)).isEqualTo((short) 200);
228+
229+
// null patches → every position returns the fill (getShort, getInt and fold paths)
230+
var nf = new LazySparseShortArray(I16, 3, (short) 7, 7, null, null, 0L);
231+
assertThat(nf.getShort(0)).isEqualTo((short) 7);
232+
assertThat(nf.getInt(0)).isEqualTo(7);
233+
assertThat(nf.fold(0L, java.lang.Long::sum)).isEqualTo(21L);
234+
}
235+
}
236+
237+
@Nested
238+
class Bool {
239+
240+
@Test
241+
void getBooleanPatchAndFill() {
242+
// Given — fill false, single patch true at index 2
243+
BoolArray values = bools(true);
244+
Array indices = ints(2);
245+
var sut = new LazySparseBoolArray(BOOL, 4, false, values, indices, 0L);
246+
247+
// When / Then
248+
assertThat(sut.getBoolean(0)).isFalse(); // fill (p<0)
249+
assertThat(sut.getBoolean(2)).isTrue(); // patch
250+
}
251+
252+
@Test
253+
void forEachBooleanEmitsFillAndPatches() {
254+
// Given
255+
BoolArray values = bools(true);
256+
Array indices = ints(2);
257+
var sut = new LazySparseBoolArray(BOOL, 4, false, values, indices, 0L);
258+
259+
// When
260+
var seen = new ArrayList<Boolean>();
261+
sut.forEachBoolean(seen::add);
262+
263+
// Then
264+
assertThat(seen).containsExactly(false, false, true, false);
265+
}
214266
}
215267

216268
@Nested

reader/src/test/java/io/github/dfa1/vortex/reader/array/LazyZigZagIntArrayTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,20 @@ void foldSumApplies() {
6565
// Then
6666
assertThat(sum).isZero();
6767
}
68+
69+
@Test
70+
void materializeDecodesAllRows() {
71+
// Given
72+
LazyZigZagIntArray sut = of(0, 1, 2, 3, 4);
73+
74+
// When
75+
try (Arena arena = Arena.ofConfined()) {
76+
MemorySegment seg = sut.materialize(arena);
77+
78+
// Then — materialized rows match the lazy getter
79+
for (int i = 0; i < 5; i++) {
80+
assertThat(seg.getAtIndex(LE_INT, i)).as("row %d", i).isEqualTo(sut.getInt(i));
81+
}
82+
}
83+
}
6884
}

0 commit comments

Comments
 (0)