Announcing hegel-clj, a Clojure interface for the Hegel testing library
hegel-clj is a Clojure interface for Hegel[1], a new cross-platform library for generative testing that provides deterministic generators and shrinking tactics. The author explains that complex generators in test.check[2] often get stuck during shrinking[3], where a failing value is reduced to a smaller one, and the usual cause is bind, an operation that draws a random value and uses it to build a new generator.
In the author's example, a generator draws a size and then builds a vector of that size, and shrinking ends with a 39-element vector like [0 0 ... 42 0] instead of the single value 42. Each tried size draws new random elements, so most sizes lose the 42 and shrinking gets stuck. The author notes that experienced test.check users try to avoid bind and let, but these are inescapable for many problems.
The Hypothesis team in Python takes another approach: its generators produce a single value and re-run the generator to find something similar but smaller, an approach that is the foundation of Hegel. In hegel-clj, the test! function runs a body that throws an exception when the test fails, and Hegel searches for values that make it throw and then shrinks them. In the author's example, the smallest failing case was a single draw of 1, which made (even? 1) throw. The author says the library is ready for people to try.
Read the original aphyr.comDiscussion
Sources
-
aphyr.com
Announcing Hegel-clj


