Skip to content

Add generators for OptionalInt, OptionalLong and OptionalDouble - #33

Merged
esauro merged 2 commits into
hegeldev:mainfrom
blemale:primitive-optionals
Oct 16, 2026
Merged

esauro merged 2 commits into
hegeldev:mainfrom
blemale:primitive-optionals

Conversation

@blemale

@blemale blemale commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #27.

Summary

  • Adds Generators.optionalInts(Generator<Integer>), optionalLongs(Generator<Long>) and optionalDoubles(Generator<Double>). Each generates either an empty primitive optional or one wrapping a value from the given generator, and shrinks toward empty, like optional.
  • forType / records now derive OptionalInt, OptionalLong and OptionalDouble (from integers(), longs(), doubles()), so record Stats(long count, OptionalLong max, OptionalDouble mean) derives without an override.

Review notes

These are new names rather than overloads of optional, as discussed in the issue. Because IntegerGenerator implements Generator<Integer>, an optional(IntegerGenerator) overload would be picked over the generic one, so existing calls like optional(integers().min(0).max(3)) would silently change from Optional<Integer> to OptionalInt, while optional(integers().filter(...)) would not.

Testing

  • ConformanceTest.optional{Ints,Longs,Doubles}BoundsAndShrinking: for each type, values stay within the inner generator's bounds, an unconstrained draw shrinks to empty, and a present value shrinks to the inner generator's lower bound.
  • GeneratorSmokeTest: draws one value of each type.
  • DerivationTest.derivesPrimitiveOptionals: derives a record with all three.
  • mvn verify passes locally (both backends, 100% coverage gate); spotless:check clean.

Add Generators.optionalInts, optionalLongs and optionalDoubles, which
generate the primitive optionals the same way optional generates
Optional<T>, and derive them in forType/records.

Closes hegeldev#27
@blemale
blemale force-pushed the primitive-optionals branch from 0c4aa96 to a681b67 Compare October 12, 2026 13:39
@blemale
blemale marked this pull request as ready for review October 12, 2026 13:48
@blemale

blemale commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

The test (java 25) failure looks flaky and unrelated to this PR. All tests pass in that job, only the JaCoCo check on hegel drops to 99%, while the java 22, macOS and Windows jobs pass the 100% gate on the same commit.

I couldn't reproduce it on Linux x86-64 with Temurin 25.0.4, the JDK the failing job used. One full mvn -B verify run and 10 more runs of the hegel module all reached 100% coverage. Script, run from the repository root:

git archive HEAD | docker run --rm -i --platform linux/amd64 -e CI=true \
  maven:3.9-eclipse-temurin-25 bash -c '
    mkdir /src && tar -x -C /src && cd /src
    apt-get -qq update && apt-get -qq install -y python3 >/dev/null
    mvn -B verify'

Could someone re-run the failed job?

@esauro

esauro commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

It passed this time and it passed for me locally too several times

@esauro
esauro merged commit 38d555a into hegeldev:main Oct 16, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add generators for OptionalInt, OptionalLong and OptionalDouble

2 participants