-
Notifications
You must be signed in to change notification settings - Fork 87
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
Fixed LedgerPeers generators #5092
Conversation
When properties are defined as functions, it is easier to paste shrinked counterexamples.
df9dbc4
to
46c736f
Compare
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.
LGTMjust some small comments
ouroboros-network/testlib/Test/Ouroboros/Network/Diffusion/Testnet/Cardano.hs
Outdated
Show resolved
Hide resolved
ouroboros-network/testlib/Test/Ouroboros/Network/Diffusion/Testnet/Cardano.hs
Outdated
Show resolved
Hide resolved
<- listOf1 (listOf1 (sublistOf (makeRelayAccessPoint <$> ledgerPeersRelays) | ||
`suchThat` (not . null))) |
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.
using suchThat
might make the generator slower. Perhaps we can generate directly from NonEmpty
?
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.
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.
we need sublistOf1
which is not in QuickCheck
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.
Added 😁, for now it lives in this file; once we'll need it elsewhere we can move it to ouroboros-network-testing
.
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.
Right, that's because you can't have a sublistOf1 of the empty list. I took a look at your implementation. I found this one to be simpler
sublistOf1 :: NonEmpty a -> Gen [a]
sublistOf1 (NonEmpty xs) = do
(e:listWithoutE) <- pick xs
subList <- sublistOf listWithoutE
pure (e:subList)
where
pick :: NonEmpty a -> Gen (a, [a])
pick (NonEmpty as) = do
i <- choose (0, length as - 1)
case splitAt i as of
(l, (a:as')) -> pure (a, l ++ as')
(l, []) -> pick l
I wrote it here without any LSP help, might need some help compiling 😄
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.
My implementation preserves the order of elements.
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.
Ah right we have to preserve that, it shouldn't be hard to tweak mine to fix it without requiring the impartiality from yours, no?
ouroboros-network/testlib/Test/Ouroboros/Network/LedgerPeers.hs
Outdated
Show resolved
Hide resolved
The `naLedgerPeers` requires a script of ledger peers. We used to generate just a single ledger peer, instead generate a list of them. The ledger peer generation had a devision by zero error, which is fixed in this commit as well.
46c736f
to
2e041df
Compare
Description
Fixes: #5091
Checklist
Quality
Maintenance
ouroboros-network
project.