Skip to content

Add tests for shrinking behavior of generators - #229

Merged
whatyouhide merged 1 commit into
mainfrom
claude/stream-data-issue-160-f8773c
Jul 12, 2026
Merged

Add tests for shrinking behavior of generators#229
whatyouhide merged 1 commit into
mainfrom
claude/stream-data-issue-160-f8773c

Conversation

@whatyouhide

Copy link
Copy Markdown
Owner

Closes #160.

What changed

Removes the long-standing # TODO: test shrinking from StreamDataTest and adds shrinking tests for essentially every shrinkable generator, each placed alongside the generator's existing tests (inside its describe block where one exists, as a sibling test otherwise — same pattern already used by one_of/1 and shuffle/1).

The existing shrink/1 helper (originally taken from the issue) is extended to shrink/2 with an optional predicate: it returns the smallest value the generator shrinks to for which the predicate holds, by running check_all/3 with a property that fails exactly on those values. This enables classic assertions like:

assert shrink(integer(), &(&1 >= 42)) == 42
assert shrink(list_of(integer()), &(length(&1) >= 3)) == [0, 0, 0]

It also includes the higher-order property suggested in the issue: integer(bound1..bound2) shrinks to the smallest absolute value in the range (0 if the range straddles zero, otherwise the bound closest to zero — per the documented behavior, not min(bound1, bound2) as the issue sketch guessed).

Notes for review

  • Each test asserts what the generator's own "Shrinking" doc section promises: integer/0 → 0, boolean/0false, list_of/2[] (respecting :min_length), member_of/1/frequency/1/one_of/1 → earliest entries, optional_map/1%{}, filter/2 only shrinks within the predicate, unshrinkable/1/repeatedly/1 visit zero shrink nodes, and so on.
  • For float/1, only bound-respecting is asserted: the docs explicitly say floats shrink towards "simpler" values, not smaller ones, and the exact shrink targets are implementation artifacts.
  • All shrinks run from :os.timestamp() seeds, so every exact-value assertion was verified deterministic across 50 random seeds before being encoded, and the suite was run repeatedly with different ExUnit seeds to check for flakiness.
  • The helper bumps max_runs/max_shrinking_steps to 1000 so predicate-based shrinks reliably find a failing value to shrink from.

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 302

Coverage increased (+1.1%) to 94.457%

Details

  • Coverage increased (+1.1%) from the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 451
Covered Lines: 426
Line Coverage: 94.46%
Coverage Strength: 11758.51 hits per line

💛 - Coveralls

@whatyouhide
whatyouhide merged commit d356b50 into main Jul 12, 2026
2 checks passed
@whatyouhide
whatyouhide deleted the claude/stream-data-issue-160-f8773c branch July 12, 2026 16:02
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.

Test shrinking

2 participants