33
44module Test.Database.LSMTree.Generators (
55 tests
6- , prop_arbitraryAndShrinkPreserveInvariant
7- , prop_forAllArbitraryAndShrinkPreserveInvariant
8- , deepseqInvariant
96 ) where
107
11- import Control.DeepSeq (NFData , deepseq )
128import Data.Bifoldable (bifoldMap )
139import Data.Coerce (coerce )
1410import qualified Data.Map.Strict as Map
@@ -26,9 +22,10 @@ import Database.LSMTree.Internal.RawBytes (RawBytes (..))
2622import Database.LSMTree.Internal.Serialise
2723
2824import qualified Test.QuickCheck as QC
29- import Test.QuickCheck (Arbitrary ( .. ), Gen , Property , Testable ( .. ) )
25+ import Test.QuickCheck (Property )
3026import Test.Tasty (TestTree , localOption , testGroup )
3127import Test.Tasty.QuickCheck (QuickCheckMaxSize (.. ), testProperty )
28+ import Test.Util.Arbitrary
3229
3330tests :: TestTree
3431tests = testGroup " Test.Database.LSMTree.Generators" [
@@ -54,27 +51,6 @@ tests = testGroup "Test.Database.LSMTree.Generators" [
5451 ]
5552 ]
5653
57- prop_arbitraryAndShrinkPreserveInvariant ::
58- forall a . (Arbitrary a , Show a ) => (a -> Bool ) -> [TestTree ]
59- prop_arbitraryAndShrinkPreserveInvariant =
60- prop_forAllArbitraryAndShrinkPreserveInvariant arbitrary shrink
61-
62- prop_forAllArbitraryAndShrinkPreserveInvariant ::
63- forall a . Show a => Gen a -> (a -> [a ]) -> (a -> Bool ) -> [TestTree ]
64- prop_forAllArbitraryAndShrinkPreserveInvariant gen shr inv =
65- [ testProperty " Arbitrary satisfies invariant" $
66- property $ QC. forAllShrink gen shr inv
67- , testProperty " Shrinking satisfies invariant" $
68- property $ QC. forAll gen $ \ x ->
69- case shr x of
70- [] -> QC. label " no shrinks" $ property True
71- xs -> QC. forAll (QC. growingElements xs) inv
72- ]
73-
74- -- | Trivial invariant, but checks that the value is finite
75- deepseqInvariant :: NFData a => a -> Bool
76- deepseqInvariant x = x `deepseq` True
77-
7854prop_packRawBytesPinnedOrUnpinned :: Bool -> [Word8 ] -> Bool
7955prop_packRawBytesPinnedOrUnpinned pinned ws =
8056 packRawBytesPinnedOrUnpinned pinned ws == RawBytes (VP. fromList ws)
0 commit comments