Introduce invariant check.#63
Conversation
| 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.
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.
Could you, please, add documentation to what this invariant actually checks? It's not clear to me what is the invariant of TypeRepMap
|
|
||
| invariantCheck :: TypeRepMap f -> Bool | ||
| invariantCheck TypeRepMap{..} = getAll (check 0) where | ||
| sz = sizeofPrimArray fingerprintAs |
There was a problem hiding this comment.
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. |
chshersh
left a comment
There was a problem hiding this comment.
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. |
chshersh
left a comment
There was a problem hiding this comment.
Thanks! This check looks useful!
This check provides if internal structure maintains required
invariants and can be used when changing the logic of the
modification functions.