This is a long-standing Hard Problem.
h2. The Problem
The classic example is shrinking a 2d matrix with a poisoned element in it:
(def gen-matrix
(gen/let [width gen/nat]
(gen/vector (gen/vector gen/large-integer width))))
(quick-check 10000
(prop/for-all [matrix gen-matrix]
(->> matrix
(apply concat)
(not-any? #{42}))))
;; =>
{:result false,
:seed 1466646880334,
:failing-size 16,
:num-tests 17,
:fail [[[290 42 10 3 1 3 196]
[-1793 3484 -5795 -206 -1 -8 464]
[2 3 -1951 -761 -28829 5518 1]
[-32 4477 1 -4086 0 1640 -22185]
[-485 3156 -625 4082 -2 -845 513]
[-3 -1 26 323 232 5 -1]
[32 51 -1 240 -1814 0 -190]
[2417 -4239 326 -4096 -8 1898 75]
[-509 1 0 466 199 -1 10]
[-23 5838 -441 30741 -6724 -1169 -171]
[-4 3974 -1432 -4 698 -56 1210]
[-2148 -6526 -1 453 19 -5343 461]]],
:shrunk {:total-nodes-visited 31,
:depth 8,
:result false,
;; would be better if shrunk to [[[42]]]
;;
;; note that it's plausible the smallest value here could have the same width (7)
;; as the original failure -- the only reason it was able to shrink the width at
;; all was that it got lucky by generating an entirely new matrix with the smaller
;; width that happened to have 42 in it
:smallest [[[0 42 0]]]}}
h2. Ideas
-
https://twitter.com/jacobstanley/status/745790758972624896
-
https://twitter.com/DRMacIver/status/737390842462212096
- a best-effort approach to reuse values generated in the last failing case
-- if we recorded the things generated from each sub-generator of a composite generator, and then used generator equality to try to reproduce those values when running generators during shrinking...it would be messy but I think the mess would be invisible to users