Skip to content

Deriver: qcheck and qcheck2 - #209

Merged
jmid merged 78 commits into
c-cube:masterfrom
vch9:qcheck-and-qcheck2
Nov 7, 2022
Merged

Deriver: qcheck and qcheck2#209
jmid merged 78 commits into
c-cube:masterfrom
vch9:qcheck-and-qcheck2

Conversation

@vch9

@vch9vch9 commented Dec 13, 2021

Copy link
Copy Markdown
Contributor

Closes#190

This PR introduces two derivation plugins:

  • qcheck
  • qcheck2

The code and test is duplicated, in the vast majority it's only a renaming to QCheck to QCheck2 (excepts for fun_nary)

- utop # type t =intvalgen : tQCheck.Gen.t=<fun>valarb : tQCheck.arbitrary=
{QCheck.gen =<fun>; print =None; small =None; shrink =None;
collect =None; stats =[]}
─( 15:46:16 )─<command2>─────
-utop # type t =int [@@deriving qcheck2];;
typet = intvalgen : tQCheck2.Gen.t=<abstr>

This it not ideal as we only derive generators then call make on them, the best would be to use arbitrary for primitive types as they also have printers, shrinkers etc.

However after #195, #208 and this one, I'm getting tired of writing boilerplate code, but I will eventually do this in the future :)

@vch9vch9 changed the title Deriver: qcheck and qcheck2WIP: Deriver: qcheck and qcheck2Dec 13, 2021
@vch9
vch9force-pushed the qcheck-and-qcheck2 branch from a48a357 to 14be7e2CompareDecember 15, 2021 14:47
@vch9vch9 changed the title WIP: Deriver: qcheck and qcheck2Deriver: qcheck and qcheck2Dec 15, 2021
@vch9vch9 mentioned this pull request Jan 4, 2022
5 tasks
let ty = Ldot (Ldot (Lident "QCheck", "Gen"), "t")
let ty = function
| `QCheck -> Ldot (Ldot (Lident "QCheck", "Gen"), "t")
| `QCheck2 -> Ldot (Ldot (Lident "QCheck2", "Gen"), "t")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would introducing a VERSION module and changing these to use a to_module function improve this duplication?

module type VERSION = sig
type t
val version : t
val to_module : t -> label
end
type version = [`QCheck | `QCheck2]
let to_module = function
| `QCheck -> "QCheck"
| `QCheck2 -> "QCheck2"

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're right, I believe we would never have more than 2 versions but that'd simplify the code a bit.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, I don't see the real benefit of the module type VERSION.
Isn't:

typeversion = [`QCheck | `QCheck2]
letto_module : version -> string =function|`QCheck -> "QCheck"|`QCheck2 -> "QCheck2"lettyversion=Ldot (Ldot (Lident (to_module version), "Gen"), "t")
...
moduleMake (Version : sig val version : version end) =struct

enough?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be enough, I would go with that.
Making it a module type might be slightly tidier if more than 2 versions were expected or there were other places that needed that type. In my hacking it didn't seem worthwhile.

@vch9
vch9force-pushed the qcheck-and-qcheck2 branch from 14be7e2 to 8ce4ca7CompareJanuary 24, 2022 17:07
@vch9

vch9 commented Jan 24, 2022

Copy link
Copy Markdown
ContributorAuthor

Used @tmcgilchrist suggestion to reduce the code duplication and rebased to master. The commits should be squashed on merge, I'm not sure each of them compile and it's not that important if they're split.

@vch9
vch9force-pushed the qcheck-and-qcheck2 branch from 8ce4ca7 to b1c8290CompareJuly 1, 2022 12:17
n-osborneand others added 29 commits November 2, 2022 10:28
Fix "unknown option" error message from runner
Update expected 32bit output for test_gen_no_shrink
@jmid
jmid merged commit 344f4d7 into c-cube:masterNov 7, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deriver: support qcheck and qcheck2

6 participants

@vch9@tmcgilchrist@olafhering@jmid@c-cube@n-osborne