Skip to content

Generating expr #157

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

Closed

Conversation

phadej
Copy link
Contributor

@phadej phadej commented Jun 13, 2017

This is try to fix #154

We could rewrite all [Key] or [(Key, Int)] based properties into Expr Key () or Expr Key Int based ones, respectively. I think including union is worth it, as it is has non-trivial implementation.

First commit is from #156.

@phadej phadej force-pushed the generating-expr branch from 744ffdb to 47e5b7f Compare June 13, 2017 13:14
Copy link
Collaborator

@treeowl treeowl left a comment

Choose a reason for hiding this comment

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

I'm not quite convinced this fully solves the problem. We want to guarantee (as best we can) that every valid HashMap tree is available to the Arbitrary instance. Do we have good reasons to believe that all such trees can be generated by this language?

An alternative, more complicated, approach (but quite possibly the right one) would be to use an expression language that includes all primitive operations, interpreting it using HashMap or HashSet and also (say) Data.Map or Data.Set.

One of the key ideas of the containers test suite is that all the invariants for each data structure are expressed in a single valid function. In this context, that would allow your Expr interpretation to find the smallest invalid subexpression, rather than waiting for that invariant failure to show up as a hard-to-debug semantic error.

arb n = oneof $ leafs ++
[ liftA3 ExprInsert arbitrary arbitrary (arb (n - 1))
, liftA2 ExprDelete arbitrary (arb (n - 1))
, liftA2 ExprUnion (arb (n `div` 2)) (arb (n - n `div` 2))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why div and not quot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prelude Test.QuickCheck> 3 `div` 2 + 3 `quot` 2
2

@phadej
Copy link
Contributor Author

phadej commented Jun 14, 2017

I'm not quite convinced this fully solves the problem. We want to guarantee (as best we can) that every valid HashMap tree is available to the Arbitrary instance. Do we have good reasons to believe that all such trees can be generated by this language?

I don't know, I looked at non-trivial -> HashMap k v functions in Base.hs module.

An alternative, more complicated, approach (but quite possibly the right one) would be to use an expression language that includes all primitive operations, interpreting it using HashMap or HashSet and also (say) Data.Map or Data.Set.

AFAICS the insert, delete and union are a good start.

One of the key ideas of the containers test suite is that all the invariants for each data structure are expressed in a single valid function. In this context, that would allow your Expr interpretation to find the smallest invalid subexpression, rather than waiting for that invariant failure to show up as a hard-to-debug semantic error.

That's a good idea, but it can be added independently. I'm not 100% sure what are the invariants.

@treeowl
Copy link
Collaborator

treeowl commented Jun 26, 2017

Can you rebase this, please?

@phadej phadej force-pushed the generating-expr branch from 47e5b7f to 4862faa Compare June 26, 2017 16:49
@phadej
Copy link
Contributor Author

phadej commented Jun 26, 2017

rebased

@phadej
Copy link
Contributor Author

phadej commented Jul 16, 2017

ping @treeowl, is there something I can do to get this off my "open PR" -list? :)

@treeowl
Copy link
Collaborator

treeowl commented Jan 23, 2018

Uh, I seem to have forgotten about this. I'll try to get to it in the next couple days.

@phadej
Copy link
Contributor Author

phadej commented Apr 15, 2019

This seems to be still forgotten...

@treeowl
Copy link
Collaborator

treeowl commented Apr 15, 2019 via email

@phadej phadej closed this Apr 15, 2019
@phadej phadej deleted the generating-expr branch April 15, 2019 21:04
Sign up for free to 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.

Arbitrary instance for HashMap is unfortunate
2 participants