Skip to content

Commit 214db42

Browse files
committed
Extract non-discarding implies QuickCheck utility
1 parent f25ea0b commit 214db42

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

ouroboros-consensus-diffusion/changelog.d/20240425_110304_alexander.esgen_customize_prefer_candidate.md

Whitespace-only changes.

ouroboros-consensus-diffusion/src/unstable-diffusion-testlib/Test/ThreadNet/General.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import Test.Util.HardFork.Future (Future)
7474
import Test.Util.Orphans.Arbitrary ()
7575
import Test.Util.Orphans.IOLike ()
7676
import Test.Util.Orphans.NoThunks ()
77+
import Test.Util.QuickCheck
7778
import Test.Util.Range
7879
import Test.Util.Shrink (andId, dropId)
7980
import Test.Util.Slots (NumSlots (..))
@@ -674,10 +675,6 @@ prop_general_internal syncity pga testOutput =
674675
| ((s1, _, max1), (s2, min2, _)) <- orderedPairs extrema
675676
]
676677
where
677-
-- QuickCheck's @==>@ 'discard's the test if @p1@ fails; that's not
678-
-- what we want
679-
implies p1 p2 = not p1 .||. p2
680-
681678
-- all pairs @(x, y)@ where @x@ precedes @y@ in the given list
682679
orderedPairs :: [a] -> [(a, a)]
683680
orderedPairs = \case

ouroboros-consensus/src/unstable-consensus-testlib/Test/Util/QuickCheck.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Test.Util.QuickCheck (
2828
-- * Convenience
2929
, collects
3030
, forAllGenRunShrinkCheck
31+
, implies
3132
) where
3233

3334
import Control.Monad.Except
@@ -218,3 +219,10 @@ shrinkNP g f np = npToSListI np $ cshrinkNP (Proxy @Top) g f np
218219

219220
collects :: Show a => [a] -> Property -> Property
220221
collects = repeatedly collect
222+
223+
-- | QuickCheck's '==>' 'discard's the test if @p1@ fails; this is sometimes not
224+
-- what we want, for example if we have other properties that do not depend on
225+
-- @p1@ being true.
226+
implies :: Testable prop => Bool -> prop -> Property
227+
implies p1 p2 = not p1 .||. p2
228+
infixr 0 `implies`

0 commit comments

Comments
 (0)