Are there any good resources for writing shrinkers...
# kotlintest
b
Are there any good resources for writing shrinkers in a more principled way? It seems like writing a shrinker for custom datatypes is usually more efficient than using a predefined shrinker. But some PBT tools attempt to use automatic shrinking and caching, so maybe the benefits are negligible, cf. https://github.com/JetBrains/jetCheck. There is an interesting discussion about the benefits of integrating shrinking vs. using a predefined strategy: https://hypothesis.works/articles/integrated-shrinking/ https://www.well-typed.com/blog/2019/05/integrated-shrinking/ I was curious about the default shrinker implementations in KotlinTest: https://github.com/kotlintest/kotlintest/blob/master/kotest-assertions/src/commonMain/kotlin/io/kotest/properties/shrinking/DoubleShrinker.kt https://github.com/kotlintest/kotlintest/blob/master/kotest-assertions/src/commonMain/kotlin/io/kotest/properties/shrinking/IntShrinker.kt Is there a good reason for using those ratios in the geometric series?
j
Integrated shrinking has only one disadvantage over custom/predefined shrinking and that is that dependent composition (flatMap/bind) produces worse results. This can be circumvented. The best resource for integrated shrinking is probably the well-typed article you linked, haskell hedgehog's source code is also good. Hypothesis uses yet another different approach based on heuristics afaik, but I am not too familiar with that.
s
The current shrinking logic in kotlintest 3.x is poor, but for 4.0 we are overhauling all the property test stuff to move it ahead of other libraries. We’re looking for feedback on the current design. https://github.com/kotlintest/kotlintest/issues/1121 @breandan please be brutal in your feedback