krestenkrab / triq

Trifork QuickCheck
http://krestenkrab.github.com/triq/
Apache License 2.0
281 stars 54 forks source link

More aggressive shrinker for choose/2 #31

Closed jhlywa closed 9 years ago

jhlywa commented 10 years ago

The old shrinker would simply subtract one from the current value, which was ineffective when shrinking large ranges (e.g. choose(0, 16#ffffffff)). This new shrinker converges towards min by repeatedly halving the difference between current value and min. Below are outputs from sample shrink:

Old Shrinker

$ erl -pa ebin/ -noshell \
      -eval "triq_dom:sampleshrink(triq_dom:choose(0,16#ffffffff))" \
      -eval "init:stop()"
1905181424
[1905181423]
[1905181422]
[1905181421]
[1905181420]
[1905181419]
[1905181418]
[1905181417]
[1905181416]
[1905181415]
[1905181414]
% goes on forever

New Shrinker

$ erl -pa ebin/ -noshell \
      -eval "triq_dom:sampleshrink(triq_dom:choose(0,16#ffffffff))"  \
      -eval "init:stop()"
1905181424
[952590712]
[476295356]
[238147678]
[119073839]
[59536919]
[29768459]
[14884229]
[7442114]
[3721057]
[1860528]
[930264]
[465132]
[232566]
[116283]
[58141]
[29070]
[14535]
[7267]
[3633]
[1816]
[908]
[454]
"ã"
"q"
"8"
[28]
[14]
[7]
[3]
[1]
[0]
ghost commented 10 years ago

Looks reasonable to me.