Comments (3)
Acknowledged! 🙂
In a past role teaching this stuff I prepared slides to explain the Gen.t
vs arbitrary
difference.
See https://janmidtgaard.dk/quickcheck/slides/lec03.pdf from p.48 of the pdf (labeled 21/48 in the bottom right corner).
The slides summarize my own view: Gen.t
is purely for generation and nothing else, while arbitrary
is a generator packaged up with a corresponding printer, shrinker, etc.
With that in mind, e.g., a string arbitrary
combinator needing a 'size generator' we really only need "something that can generate an int
size", i.e., an int Gen.t
.
Whereas my old slides go top-down, the relevant Cornell book chapter instead explains this bottom-up, starting from "pure generation" and explains arbitrary
as their enhancement IIRC.
Finally I should mention that QCheck2
with integrated shrinking, doesn't have the same distinction because generators and shrinkers are merged into one common (lazy tree) structure.
For example: I need a small list of key-value pairs. Should I use the Gen.t or arbitrary combinators to define this?
Tests built with Test.make
accept an arbitrary
in order to be able to print (and shrink) any counterexamples.
As such I expect you would want something like the following (using char
keys and bool
values):
list_of_size Gen.small_nat (pair char bool) : (char * bool) list QCheck.arbitrary =
Notice how this uses Gen.t
for size generation, for the reason explained above.
I hope this helps! As always, PRs to improve the documentation are very welcome! 🙏😃
from qcheck.
The documentation on the slides is helpful; maybe include a link or the slides in this repository. I believe this kind of high-level explanation would at the top of the MLI file would help. Something that is not obvious: is QCheck2
an older or more recent version? The current release is 0.21.x
so I fail to see the connection and which interface should new code target?
from qcheck.
The documentation on the slides is helpful; maybe include a link or the slides in this repository. I believe this kind of high-level explanation would at the top of the MLI file would help.
That's a good point and a constructive suggestion, thanks!
Something that is not obvious: is QCheck2 an older or more recent version? The current release is 0.21.x so I fail to see the connection and which interface should new code target?
Indeed. QCheck2 offers integrated shrinking (see #106 #109 and #116 for details).
It is a newer development offering "shrinking for free", meaning an end user does not need to write a boilerplate shrinker for 'custom generators' (think: 2 for the price of 1).
QCheck2 isn't as battle tested as the older QCheck(1).
I started an effort to strengthen both implementations by adding tests in #153 and collecting a suite of shrinker benchmarks in #177 about 2 years back.
For this reason I chose to go with QCheck(1) for https://github.com/ocaml-multicore/multicoretests 1.5 years ago.
One day:tm: (famous last words) I want to switch it to QCheck2.
I believe @vch9 has already switched to using QCheck2 to test Tezos so it may indeed be ready for production.
The QCheck(1) vs. QCheck2 distinction could certainly also be made clearer in the documentation...
Finally I'm realizing that https://c-cube.github.io/qcheck/0.21/qcheck-core/QCheck2/index.html is perhaps not as easily reachable from https://c-cube.github.io/qcheck/ as one could hope for.
from qcheck.
Related Issues (20)
- Disable QCheck2 shrinker with a parameter HOT 3
- Generator reproducability with function generators
- Add range_subset, pos_split2, nat_split2, pos_split, nat_split to QCheck2
- QCheck int shrinker produces duplicates
- Share some code between QCheck and QCheck2
- Missing QCheck.Shrink.bool HOT 1
- Extend expect tests to OCaml 5.0
- count cannot be zero HOT 4
- custom stopping criteria for tests HOT 1
- QCheck.numeral_string may shrink to non-numerals HOT 1
- Rename default branch HOT 1
- Add warning to Gen.generate* functions
- Add opam package descriptions
- Non-minimal list counter examples HOT 2
- ppx_deriving_qcheck cannot derive a generator from a recursive type declaration with containers HOT 4
- missing usage with dune HOT 5
- Lower ppx_deriving_qcheck's qcheck dependency
- Switch to ocaml-ci
- Less exhaustive string shrinking HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qcheck.