From 02c70cfc63b7c6843ad7feb8e6d3748a3fc6de96 Mon Sep 17 00:00:00 2001 From: Davide Angelocola Date: Sat, 20 Jun 2026 15:18:55 +0200 Subject: [PATCH] test(reader): replace LayoutKindTest boolean matrix with a kind enum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The 5-boolean-per-row provider was an identity matrix encoding a single fact: "exactly this kind's predicate is true." Replace it with a Kind enum pairing each encoding id with its predicate, driven by @EnumSource; the assertion `other == kind` expresses the intent directly. Same mutation coverage — every predicate is still asserted true for its own id and false for the others, and the Layout kind mutants stay fully killed. Co-Authored-By: Claude Opus 4.8 --- .../dfa1/vortex/reader/LayoutKindTest.java | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/reader/src/test/java/io/github/dfa1/vortex/reader/LayoutKindTest.java b/reader/src/test/java/io/github/dfa1/vortex/reader/LayoutKindTest.java index 7d49d9c1..82901d75 100644 --- a/reader/src/test/java/io/github/dfa1/vortex/reader/LayoutKindTest.java +++ b/reader/src/test/java/io/github/dfa1/vortex/reader/LayoutKindTest.java @@ -2,48 +2,53 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.EnumSource; import java.util.List; -import java.util.stream.Stream; +import java.util.function.Predicate; import static org.assertj.core.api.Assertions.assertThat; /// Pins the [Layout] encoding-kind predicates (`isFlat`, `isChunked`, `isStruct`, `isZoned`, /// `isDict`). [ScanIterator] dispatches layout-tree traversal on these, so a predicate that -/// silently returns a constant would route a whole layout family down the wrong decode path. -/// One layout per encoding id, asserting the matching predicate is `true` and every other is -/// `false` — which fixes each method's return to its `encodingId` rather than a constant. +/// silently returned a constant would route a whole layout family down the wrong decode path. +/// For a layout of each kind, exactly its own predicate must be `true` and every other `false`, +/// which fixes each method's return to its `encodingId` rather than a constant. class LayoutKindTest { + /// Each layout kind paired with its encoding id and the predicate that should recognise it. + private enum Kind { + FLAT(Layout.FLAT, Layout::isFlat), + CHUNKED(Layout.CHUNKED, Layout::isChunked), + STRUCT(Layout.STRUCT, Layout::isStruct), + ZONED(Layout.ZONED, Layout::isZoned), + DICT(Layout.DICT, Layout::isDict); + + private final String encodingId; + private final Predicate predicate; + + Kind(String encodingId, Predicate predicate) { + this.encodingId = encodingId; + this.predicate = predicate; + } + } + private static Layout layout(String encodingId) { return new Layout(encodingId, 0L, null, List.of(), List.of()); } - static Stream kinds() { - // (encodingId, isFlat, isChunked, isStruct, isZoned, isDict) - return Stream.of( - Arguments.of(Layout.FLAT, true, false, false, false, false), - Arguments.of(Layout.CHUNKED, false, true, false, false, false), - Arguments.of(Layout.STRUCT, false, false, true, false, false), - Arguments.of(Layout.ZONED, false, false, false, true, false), - Arguments.of(Layout.DICT, false, false, false, false, true)); - } + @ParameterizedTest + @EnumSource(Kind.class) + void predicate_recognisesOnlyItsOwnEncodingId(Kind kind) { + // Given — a layout carrying this kind's encoding id + Layout sut = layout(kind.encodingId); - @ParameterizedTest(name = "{0}") - @MethodSource("kinds") - void predicates_matchOnlyOwnEncodingId( - String encodingId, boolean flat, boolean chunked, boolean struct, boolean zoned, boolean dict) { - // Given - Layout sut = layout(encodingId); - - // When / Then — exactly one predicate is true, the rest false - assertThat(sut.isFlat()).as("isFlat").isEqualTo(flat); - assertThat(sut.isChunked()).as("isChunked").isEqualTo(chunked); - assertThat(sut.isStruct()).as("isStruct").isEqualTo(struct); - assertThat(sut.isZoned()).as("isZoned").isEqualTo(zoned); - assertThat(sut.isDict()).as("isDict").isEqualTo(dict); + // When / Then — only this kind's predicate is true; every other kind's is false + for (Kind other : Kind.values()) { + assertThat(other.predicate.test(sut)) + .as("%s on %s", other, kind.encodingId) + .isEqualTo(other == kind); + } } @Test @@ -51,11 +56,9 @@ void predicates_allFalse_forUnknownEncodingId() { // Given — an id matching no known layout kind Layout sut = layout("vortex.bogus"); - // When / Then — no predicate claims it - assertThat(sut.isFlat()).isFalse(); - assertThat(sut.isChunked()).isFalse(); - assertThat(sut.isStruct()).isFalse(); - assertThat(sut.isZoned()).isFalse(); - assertThat(sut.isDict()).isFalse(); + // When / Then — no kind claims it + for (Kind kind : Kind.values()) { + assertThat(kind.predicate.test(sut)).as("%s", kind).isFalse(); + } } }