Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - feat(testing): property based testing (basics) #3915

Closed
wants to merge 34 commits into from

Conversation

cipher1024
Copy link
Collaborator

@cipher1024 cipher1024 commented Aug 23, 2020

Add gen monad, sampleable and testable type classes


Taken from #2080

@cipher1024 cipher1024 added the awaiting-review The author would like community review of the PR label Aug 23, 2020
@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Aug 23, 2020
@robertylewis
Copy link
Member

A number of my comments on #2080 still apply here.

I'm also not a fan of the name arbitrary for this class, since arbitrary T is already used for the irreducible witness to an inhabited type T.

@cipher1024
Copy link
Collaborator Author

I'm also not a fan of the name arbitrary for this class, since arbitrary T is already used for the irreducible witness to an inhabited type T.

What would you rename it to? Maybe sampleable?

@cipher1024 cipher1024 added awaiting-review The author would like community review of the PR and removed awaiting-author A reviewer has asked the author a question or requested changes labels Aug 23, 2020
@robertylewis
Copy link
Member

Yes, sampleable sounds better (and more grammatical). arby can be come sample.

src/testing/slim_check/gen.lean Outdated Show resolved Hide resolved
src/testing/slim_check/gen.lean Outdated Show resolved Hide resolved
src/testing/slim_check/gen.lean Show resolved Hide resolved
src/testing/slim_check/gen.lean Show resolved Hide resolved
src/testing/slim_check/sampleable.lean Outdated Show resolved Hide resolved
test_result q :=
@add_to_counter_example (var ++ " := " ++ to_string x) _ _ h

/-- gadget used to introspect the name of bound variables -/
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain this more? I'm not seeing quickly what this gadget is doing.

src/testing/slim_check/testable.lean Outdated Show resolved Hide resolved
src/testing/slim_check/testable.lean Show resolved Hide resolved
that the goal should be satisfied with a proposition equivalent to `p`
with added annotations. -/
@[reducible, nolint unused_arguments]
def decorations_of (p : Prop) := Prop
Copy link
Member

Choose a reason for hiding this comment

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

I'm still trying to sort out exactly what's going on with these decorations, but this seems odd to have in the tactic namespace. (Note that you're still in slim_check too. If you wanted mk_decorations in _root_.tactic, it isn't there right now.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically, the instance testable (named_binder (some "x") (∀ x, p x)) generates samples for x and, when the test fails, adds x := 37 to the error message that will be printed to the user. testable is pure code and does not have access to the syntax tree (esp. the name of bound variables) of ∀ x, p x so we use a gadget to make the name "x" available.

src/testing/slim_check/testable.lean Show resolved Hide resolved
@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Aug 26, 2020
Copy link
Collaborator

@semorrison semorrison left a comment

Choose a reason for hiding this comment

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

LGTM

Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@semorrison
Copy link
Collaborator

I think this looks great now! There's documentation on the tactic that starts from the beginning, and later documentation that explains how to use the advanced features.

Shall we merge?

@digama0
Copy link
Member

digama0 commented Sep 1, 2020

I agree, the new tactic.slim_check file looks great.

bors r+

@github-actions github-actions bot added ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) and removed awaiting-review The author would like community review of the PR labels Sep 1, 2020
@robertylewis
Copy link
Member

I agree, the new tactic.slim_check file looks great.

bors r+

I agree, thanks Simon!

bors bot pushed a commit that referenced this pull request Sep 1, 2020
Add `gen` monad, `sampleable` and `testable` type classes
@bors
Copy link

bors bot commented Sep 1, 2020

Build failed:

@robertylewis
Copy link
Member

Ah, this needs to be updated for 3.19.0.

@robertylewis robertylewis added awaiting-author A reviewer has asked the author a question or requested changes and removed ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) labels Sep 1, 2020
src/data/fin.lean Outdated Show resolved Hide resolved
@robertylewis
Copy link
Member

bors merge

@bors
Copy link

bors bot commented Sep 1, 2020

👎 Rejected by label

@robertylewis robertylewis removed the awaiting-author A reviewer has asked the author a question or requested changes label Sep 1, 2020
@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Sep 1, 2020
@robertylewis
Copy link
Member

bors merge

bors bot pushed a commit that referenced this pull request Sep 1, 2020
Add `gen` monad, `sampleable` and `testable` type classes
@bors
Copy link

bors bot commented Sep 1, 2020

Pull request successfully merged into master.

Build succeeded:

@bors bors bot changed the title feat(testing): property based testing (basics) [Merged by Bors] - feat(testing): property based testing (basics) Sep 1, 2020
@bors bors bot closed this Sep 1, 2020
@bors bors bot deleted the slim-check-gen-arby branch September 1, 2020 19:30
@cipher1024
Copy link
Collaborator Author

Thank you all! Next step: smart generators for functions and testing for monadic programs (separate PRs)

PatrickMassot pushed a commit that referenced this pull request Sep 8, 2020
Add `gen` monad, `sampleable` and `testable` type classes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants