Skip to content

Commit a6983ae

Browse files
dfa1claude
andcommitted
test(reader): cover ListArray + FixedSizeListArray (were untested)
ListArraysTest exercises both list containers: shape/dtype/children accessors, child out-of-range, limited slicing (offsets-trim with shared elements; rows × fixedSize), and the no-primary-segment materialize throw. Both at 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent bcf0423 commit a6983ae

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package io.github.dfa1.vortex.reader.array;
2+
3+
import io.github.dfa1.vortex.core.DType;
4+
import io.github.dfa1.vortex.core.PType;
5+
import io.github.dfa1.vortex.core.VortexException;
6+
import org.junit.jupiter.api.Nested;
7+
import org.junit.jupiter.api.Test;
8+
9+
import java.lang.foreign.Arena;
10+
11+
import static io.github.dfa1.vortex.reader.array.TestArrays.ints;
12+
import static io.github.dfa1.vortex.reader.array.TestArrays.longs;
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
15+
16+
/// Covers the decoded list container arrays (variable-length and fixed-size).
17+
class ListArraysTest {
18+
19+
private static final DType ELEM = new DType.Primitive(PType.I32, false);
20+
21+
@Nested
22+
class VariableLength {
23+
24+
private final DType.List dtype = new DType.List(ELEM, false);
25+
private final IntArray elements = ints(10, 11, 12, 13, 14);
26+
private final Array offsets = longs(0L, 2L, 5L); // list0=[10,11], list1=[12,13,14]
27+
private final ListArray sut = new ListArray(dtype, 2, elements, offsets);
28+
29+
@Test
30+
void exposesShapeAndChildren() {
31+
// When / Then
32+
assertThat(sut.length()).isEqualTo(2);
33+
assertThat(sut.dtype()).isEqualTo(dtype);
34+
assertThat(sut.elements()).isSameAs(elements);
35+
assertThat(sut.offsets()).isSameAs(offsets);
36+
assertThat(sut.child(0)).isSameAs(elements);
37+
assertThat(sut.child(1)).isSameAs(offsets);
38+
}
39+
40+
@Test
41+
void childOutOfRangeThrows() {
42+
assertThatThrownBy(() -> sut.child(2))
43+
.isInstanceOf(VortexException.class).hasMessageContaining("child index");
44+
}
45+
46+
@Test
47+
void limitedKeepsRowsAndSharesElements() {
48+
// When
49+
ListArray limited = (ListArray) sut.limited(1);
50+
51+
// Then — one list, offsets trimmed to rows+1, elements shared
52+
assertThat(limited.length()).isEqualTo(1);
53+
assertThat(limited.offsets().length()).isEqualTo(2);
54+
assertThat(limited.elements()).isSameAs(elements);
55+
}
56+
57+
@Test
58+
void materializeThrows() {
59+
try (Arena arena = Arena.ofConfined()) {
60+
assertThatThrownBy(() -> sut.materialize(arena))
61+
.isInstanceOf(VortexException.class).hasMessageContaining("no primary segment");
62+
}
63+
}
64+
}
65+
66+
@Nested
67+
class FixedSize {
68+
69+
private final DType.FixedSizeList dtype = new DType.FixedSizeList(ELEM, 2, false);
70+
private final IntArray elements = ints(1, 2, 3, 4, 5, 6);
71+
private final FixedSizeListArray sut = new FixedSizeListArray(dtype, 3, elements);
72+
73+
@Test
74+
void exposesShapeAndChildren() {
75+
// When / Then
76+
assertThat(sut.length()).isEqualTo(3);
77+
assertThat(sut.dtype()).isEqualTo(dtype);
78+
assertThat(sut.elements()).isSameAs(elements);
79+
assertThat(sut.fixedSize()).isEqualTo(2);
80+
assertThat(sut.child(0)).isSameAs(elements);
81+
}
82+
83+
@Test
84+
void childOutOfRangeThrows() {
85+
assertThatThrownBy(() -> sut.child(1))
86+
.isInstanceOf(ArrayIndexOutOfBoundsException.class);
87+
}
88+
89+
@Test
90+
void limitedKeepsRowsTimesFixedSizeElements() {
91+
// When
92+
FixedSizeListArray limited = (FixedSizeListArray) sut.limited(2);
93+
94+
// Then — 2 rows × fixedSize 2 = 4 elements
95+
assertThat(limited.length()).isEqualTo(2);
96+
assertThat(limited.elements().length()).isEqualTo(4);
97+
}
98+
99+
@Test
100+
void materializeThrows() {
101+
try (Arena arena = Arena.ofConfined()) {
102+
assertThatThrownBy(() -> sut.materialize(arena))
103+
.isInstanceOf(VortexException.class).hasMessageContaining("no primary segment");
104+
}
105+
}
106+
}
107+
}

0 commit comments

Comments
 (0)