Add tests for shrinking behavior of generators - #229
Merged
Conversation
Coverage Report for CI Build 302Coverage increased (+1.1%) to 94.457%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #160.
What changed
Removes the long-standing
# TODO: test shrinkingfromStreamDataTestand adds shrinking tests for essentially every shrinkable generator, each placed alongside the generator's existing tests (inside itsdescribeblock where one exists, as a sibling test otherwise — same pattern already used byone_of/1andshuffle/1).The existing
shrink/1helper (originally taken from the issue) is extended toshrink/2with an optional predicate: it returns the smallest value the generator shrinks to for which the predicate holds, by runningcheck_all/3with a property that fails exactly on those values. This enables classic assertions like: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, notmin(bound1, bound2)as the issue sketch guessed).Notes for review
integer/0→ 0,boolean/0→false,list_of/2→[](respecting:min_length),member_of/1/frequency/1/one_of/1→ earliest entries,optional_map/1→%{},filter/2only shrinks within the predicate,unshrinkable/1/repeatedly/1visit zero shrink nodes, and so on.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.: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.max_runs/max_shrinking_stepsto 1000 so predicate-based shrinks reliably find a failing value to shrink from.