@@ -19,61 +19,78 @@ import Database.LSMTree.Internal.Entry
1919import Database.LSMTree.Internal.PageAcc (entryWouldFitInPage ,
2020 sizeofEntry )
2121import Database.LSMTree.Internal.RawBytes (RawBytes (.. ))
22+ import qualified Database.LSMTree.Internal.RawBytes as RB
2223import Database.LSMTree.Internal.Serialise
2324
2425import qualified Test.QuickCheck as QC
2526import Test.QuickCheck (Property )
2627import Test.Tasty (TestTree , localOption , testGroup )
27- import Test.Tasty.QuickCheck (QuickCheckMaxSize (.. ), testProperty )
28+ import Test.Tasty.QuickCheck (QuickCheckMaxSize (.. ), testProperty ,
29+ (===) )
2830import Test.Util.Arbitrary
2931
3032tests :: TestTree
3133tests = testGroup " Test.Database.LSMTree.Generators" [
3234 testGroup " PageContentFits" $
33- prop_arbitraryAndShrinkPreserveInvariant pageContentFitsInvariant
35+ prop_arbitraryAndShrinkPreserveInvariant noTags
36+ pageContentFitsInvariant
3437 , testGroup " PageContentOrdered" $
35- prop_arbitraryAndShrinkPreserveInvariant pageContentOrderedInvariant
38+ prop_arbitraryAndShrinkPreserveInvariant noTags
39+ pageContentOrderedInvariant
3640 , localOption (QuickCheckMaxSize 20 ) $ -- takes too long!
3741 testGroup " LogicalPageSummaries" $
38- prop_arbitraryAndShrinkPreserveInvariant (pagesInvariant @ Word64 )
42+ prop_arbitraryAndShrinkPreserveInvariant noTags $
43+ pagesInvariant @ Word64
3944 , testGroup " Chunk size" $
40- prop_arbitraryAndShrinkPreserveInvariant chunkSizeInvariant
41- , testGroup " Raw bytes" $
42- [testProperty " packRawBytesPinnedOrUnpinned"
43- prop_packRawBytesPinnedOrUnpinned
45+ prop_arbitraryAndShrinkPreserveInvariant noTags
46+ chunkSizeInvariant
47+ , testGroup " RawBytes" $
48+ [ testProperty " packRawBytesPinnedOrUnpinned"
49+ prop_packRawBytesPinnedOrUnpinned
4450 ]
45- ++ prop_arbitraryAndShrinkPreserveInvariant (deepseqInvariant @ RawBytes )
51+ ++ prop_arbitraryAndShrinkPreserveInvariant labelRawBytes
52+ (deepseqInvariant @ RawBytes )
53+ , testGroup " LargeRawBytes" $
54+ prop_arbitraryAndShrinkPreserveInvariant
55+ (\ (LargeRawBytes rb) -> labelRawBytes rb)
56+ (deepseqInvariant @ LargeRawBytes )
4657 , testGroup " KeyForIndexCompact" $
47- prop_arbitraryAndShrinkPreserveInvariant $
58+ prop_arbitraryAndShrinkPreserveInvariant noTags $
4859 isKeyForIndexCompact . getKeyForIndexCompact
4960 , testGroup " BiasedKeyForIndexCompact" $
50- prop_arbitraryAndShrinkPreserveInvariant $
61+ prop_arbitraryAndShrinkPreserveInvariant noTags $
5162 isKeyForIndexCompact . getBiasedKeyForIndexCompact
5263 , testGroup " lists of key/op pairs" $
53- [ testProperty " prop_distributionKOps" $
54- prop_distributionKOps
64+ prop_arbitraryAndShrinkPreserveInvariant labelTestKOps $
65+ deepseqInvariant
66+ , testGroup " helpers"
67+ [ testProperty " prop_shrinkVec" $ \ vec ->
68+ shrinkVec (QC. shrink @ Int ) vec === map VP. fromList (QC. shrink (VP. toList vec))
5569 ]
5670 ]
5771
5872prop_packRawBytesPinnedOrUnpinned :: Bool -> [Word8 ] -> Bool
5973prop_packRawBytesPinnedOrUnpinned pinned ws =
6074 packRawBytesPinnedOrUnpinned pinned ws == RawBytes (VP. fromList ws)
6175
76+ labelRawBytes :: RawBytes -> Property -> Property
77+ labelRawBytes rb =
78+ QC. tabulate " size" [showPowersOf 2 (RB. size rb)]
79+
6280type TestEntry = Entry SerialisedValue BlobSpan
6381type TestKOp = (BiasedKeyForIndexCompact , TestEntry )
6482
65- prop_distributionKOps :: [TestKOp ] -> Property
66- prop_distributionKOps kops' =
67- QC. tabulate " key occurrences (>1 is collision)" (map (show . snd ) (Map. assocs keyCounts)) $
68- QC. tabulate " key sizes" (map (showPowersOf 4 . sizeofKey) keys) $
69- QC. tabulate " value sizes" (map (showPowersOf 4 . sizeofValue) values) $
70- QC. tabulate " k/op sizes" (map (showPowersOf 4 . uncurry sizeofEntry) kops) $
71- QC. tabulate " k/op is large" (map (show . isLarge) kops) $
72- QC. checkCoverage $
73- QC. cover 50 (any isLarge kops) " any k/op is large" $
74- QC. cover 1 (ratioUniqueKeys < (0.9 :: Double )) " >10% of keys collide" $
75- QC. cover 5 (any (> 2 ) keyCounts) " has key with >2 collisions" $
76- True
83+ labelTestKOps :: [TestKOp ] -> Property -> Property
84+ labelTestKOps kops' =
85+ QC. tabulate " key occurrences (>1 is collision)" (map (show . snd ) (Map. assocs keyCounts))
86+ . QC. tabulate " key sizes" (map (showPowersOf 4 . sizeofKey) keys)
87+ . QC. tabulate " value sizes" (map (showPowersOf 4 . sizeofValue) values)
88+ . QC. tabulate " k/op sizes" (map (showPowersOf 4 . uncurry sizeofEntry) kops)
89+ . QC. tabulate " k/op is large" (map (show . isLarge) kops)
90+ . QC. checkCoverage
91+ . QC. cover 50 (any isLarge kops) " any k/op is large"
92+ . QC. cover 1 (ratioUniqueKeys < (0.9 :: Double )) " >10% of keys collide"
93+ . QC. cover 5 (any (> 2 ) keyCounts) " has key with >2 collisions"
7794 where
7895 kops = coerce kops' :: [(SerialisedKey , Entry SerialisedValue BlobSpan )]
7996 keys = map fst kops
0 commit comments