Skip to content

Commit c20c8d8

Browse files
committed
add tests for Arbitrary (Large)RawBytes
1 parent 8fc9b97 commit c20c8d8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src-extras/Database/LSMTree/Extras/Generators.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ deriving newtype instance Arbitrary SerialisedBlob
489489

490490
newtype LargeRawBytes = LargeRawBytes RawBytes
491491
deriving stock Show
492+
deriving newtype NFData
492493

493494
instance Arbitrary LargeRawBytes where
494495
arbitrary = genRawBytesSized (4096*3) >>= fmap LargeRawBytes . genSlice
@@ -501,6 +502,7 @@ instance Arbitrary LargeRawBytes where
501502
++ [ LargeRawBytes (RawBytes pvec')
502503
| let (RawBytes pvec) = rb
503504
, n <- QC.shrink (VP.length pvec)
505+
, assert (n >= 0) True -- negative values would make pvec' longer
504506
, let pvec' = VP.take n pvec VP.++ VP.replicate (VP.length pvec - n) 0
505507
, assert (VP.length pvec' == VP.length pvec) $
506508
pvec' /= pvec

test/Test/Database/LSMTree/Generators.hs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Database.LSMTree.Internal.Entry
1919
import Database.LSMTree.Internal.PageAcc (entryWouldFitInPage,
2020
sizeofEntry)
2121
import Database.LSMTree.Internal.RawBytes (RawBytes (..))
22+
import qualified Database.LSMTree.Internal.RawBytes as RB
2223
import Database.LSMTree.Internal.Serialise
2324

2425
import qualified Test.QuickCheck as QC
@@ -42,12 +43,16 @@ tests = testGroup "Test.Database.LSMTree.Generators" [
4243
, testGroup "Chunk size" $
4344
prop_arbitraryAndShrinkPreserveInvariant noTags
4445
chunkSizeInvariant
45-
, testGroup "Raw bytes" $
46+
, testGroup "RawBytes" $
4647
[ testProperty "packRawBytesPinnedOrUnpinned"
4748
prop_packRawBytesPinnedOrUnpinned
4849
]
49-
++ prop_arbitraryAndShrinkPreserveInvariant noTags
50+
++ prop_arbitraryAndShrinkPreserveInvariant labelRawBytes
5051
(deepseqInvariant @RawBytes)
52+
, testGroup "LargeRawBytes" $
53+
prop_arbitraryAndShrinkPreserveInvariant
54+
(\(LargeRawBytes rb) -> labelRawBytes rb)
55+
(deepseqInvariant @LargeRawBytes)
5156
, testGroup "KeyForIndexCompact" $
5257
prop_arbitraryAndShrinkPreserveInvariant noTags $
5358
isKeyForIndexCompact . getKeyForIndexCompact
@@ -63,6 +68,10 @@ prop_packRawBytesPinnedOrUnpinned :: Bool -> [Word8] -> Bool
6368
prop_packRawBytesPinnedOrUnpinned pinned ws =
6469
packRawBytesPinnedOrUnpinned pinned ws == RawBytes (VP.fromList ws)
6570

71+
labelRawBytes :: RawBytes -> Property -> Property
72+
labelRawBytes rb =
73+
QC.tabulate "size" [showPowersOf 2 (RB.size rb)]
74+
6675
type TestEntry = Entry SerialisedValue BlobSpan
6776
type TestKOp = (BiasedKeyForIndexCompact, TestEntry)
6877

0 commit comments

Comments
 (0)