-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement LazySequenceCopy.pop(i)
#3987
Conversation
19a7ec3
to
20417ac
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Let's wait for #3988, then rebase this on master to fix the merge conflict.
# this would be more robust as a stateful test, where each rule is a list operation | ||
# on (1) the canonical python list and (2) its LazySequenceCopy. We would assert | ||
# that the return values and lists match after each rule, and the original list | ||
# is unmodified. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this would be nice but is not merge-blocking important.
f83b58e
to
9110e34
Compare
hypothesis-python/src/hypothesis/internal/conjecture/junkdrawer.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
shrunk = minimal(st.sampled_from(LargeFlag), lambda f: bit_count(f.value) > 1) | ||
# Ideal would be (bit0 | bit1), but: | ||
# minimal(st.sets(st.sampled_from(range(10)), min_size=3)) == {0, 8, 9} # not {0, 1, 2} | ||
assert shrunk == LargeFlag.bit0 | LargeFlag.bit63 # documents actual behaviour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I remember scratching my head over this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks to your comment here, it was the only reason I looked into this 🙂
Looks like we're no longer triggering the hypothesis/hypothesis-python/src/hypothesis/internal/conjecture/engine.py Lines 379 to 382 in 4e77eea
|
9541a82
to
9368da7
Compare
that coverage was hopefully fixed in #3991. I've rebased on master, let's see how it goes |
UniqueSampledListStrategy
usesLazySequenceCopy
to pop elements from the list. BecauseLazySequenceCopy
only implemented pop-from-end, we swapped the element we wanted to pop to the end before popping. But this leaves the list in a bad state for shrinking: ifi = 0
, we just swapped the last element, which is the most complicated in shrinking order, to the front of the list, leaving it there for future passes. This means an ir tree of[0, 0, 0]
indicating the first three elements of the sequence corresponds to{0, 8, 9}
forsets(range(10))
.The solution is properly implementing
.pop(i)
. I've applied this in other places we use the swap trick, though I'm less confident thanUniqueSampledListStrategy
that this is not a behavioral change.