May 2018
Beginner to intermediate
290 pages
6h 43m
English
The final piece of the property-based testing puzzle is expressing the property. Happily, test.check provides a lovely syntax for doing just that. To start with a simple example, here we’re stating that each positive integer is smaller than the next positive integer:
| | (prop/for-all [i gen/pos-int] |
| | (< i (inc i))) |
But we’re not quite done: since we’re defining a test and not a theorem, we need to supply a limit on the number of integers we’ll try. Here we pare the infinite run of positive integers down to the first 50 produced by the pos-int generator:
| | (tc/quick-check 50 |
| | (prop/for-all [i gen/pos-int] |
| | (< i (inc i)))) |
There, the quick-check function will check the property that we specified for ...
Read now
Unlock full access