-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Introduce invariant check. #63
Conversation
test/Test/TypeRep/MapProperty.hs
Outdated
test_DeleteInvariant = prop "invariantCheck (delete k b) == True" $ do | ||
m <- forAll genMap | ||
WrapTypeable (proxy :: IntProxy n) <- forAll genTF | ||
invariantCheck (delete @n m) === True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to use assert
from the hedgehog
library instead of === True
-- Helper functions. | ||
---------------------------------------------------------------------------- | ||
|
||
invariantCheck :: TypeRepMap f -> Bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, add documentation to what this invariant actually checks? It's not clear to me what is the invariant of TypeRepMap
src/Data/TypeRepMap/Internal.hs
Outdated
|
||
invariantCheck :: TypeRepMap f -> Bool | ||
invariantCheck TypeRepMap{..} = getAll (check 0) where | ||
sz = sizeofPrimArray fingerprintAs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to write where
on the separate line and add two spaces to the function definition and also add types to the functions inside where
. This makes code more readable, and this helps a lot when trying to understand difficult and complicated code. Like this:
invariantCheck TypeRepMap{..} = getAll (check 0)
where
sz :: ???
sz = sizeofPrimArray fingerprintAs
check :: ???
check = ...
I have addressed all the comments, please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can approve and merge this PR to the master
branch. But, strictly speaking, the checked invariant is not strong. The TypeRepMap
structure satisfies the more strong invariant. Basically, array represents binary search tree. Consider the following array:
a[0] = 5
a[1] = 3 -- left son of a[0]
a[2] = 10 -- right son of a[0]
a[3] = 0 -- left son of a[1]
a[4] = 7 -- right son of a[1]
You can see that this array satisfies invariant you check, but this is a wrong binary search tree, because left branch of node with value 5
contains element that is greater than 5
.
yep, let me update the check |
self reminder (to pop up in email) |
@qnikst Friendly ping 🙂 |
This check provides if internal structure maintains required invariants and can be used when changing the logic of the modification functions.
Seems I was a bit busy, sorry for delay. I've rebased my branch atop of the master and addressed the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This check looks useful!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This check provides if internal structure maintains required
invariants and can be used when changing the logic of the
modification functions.