Skip to content

Commit c695f0c

Browse files
authored
Merge pull request #601 from IntersectMBO/jeltsch/missing-ordinary-index-tests
Complement tests of ordinary-index serialization
2 parents 014979e + f081ef3 commit c695f0c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

test/Test/Database/LSMTree/Internal/Index/Ordinary.hs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Prelude hiding (all, head, last, length, notElem, splitAt,
1111

1212
import Control.Arrow (first, (>>>))
1313
import Control.Monad.ST.Strict (runST)
14+
import qualified Data.ByteString.Lazy as LazyByteString (unpack)
1415
import Data.ByteString.Short (ShortByteString (SBS))
1516
import qualified Data.ByteString.Short as ShortByteString (length, pack)
1617
import Data.Either (isLeft)
@@ -21,7 +22,7 @@ import Data.Primitive.ByteArray (ByteArray (ByteArray), ByteArray#)
2122
import Data.Vector (Vector, all, fromList, head, last, length,
2223
notElem, splitAt, tail, takeWhile, toList, (!))
2324
import qualified Data.Vector.Primitive as Primitive (Vector (Vector), concat,
24-
force, length, singleton)
25+
force, length, singleton, toList)
2526
import Data.Word (Word16, Word32, Word64, Word8)
2627
import Database.LSMTree.Extras.Generators (LogicalPageSummaries,
2728
toAppends)
@@ -31,8 +32,8 @@ import Database.LSMTree.Extras.Index
3132
import qualified Database.LSMTree.Internal.Chunk as Chunk (toByteVector)
3233
import Database.LSMTree.Internal.Entry (NumEntries (NumEntries))
3334
import Database.LSMTree.Internal.Index.Ordinary
34-
(IndexOrdinary (IndexOrdinary), fromSBS, search,
35-
toLastKeys)
35+
(IndexOrdinary (IndexOrdinary), finalLBS, fromSBS,
36+
headerLBS, search, toLastKeys)
3637
import Database.LSMTree.Internal.Index.OrdinaryAcc (new, unsafeEnd)
3738
import Database.LSMTree.Internal.Page (PageNo (PageNo),
3839
PageSpan (PageSpan))
@@ -67,6 +68,15 @@ tests = testGroup "Test.Database.LSMTree.Internal.Index.Ordinary" $
6768
"Search for unmentioned key beyond range works"
6869
prop_searchForUnmentionedKeyBeyondRangeWorks
6970
],
71+
testGroup "Header and footer construction" $
72+
[
73+
testProperty
74+
"Header construction works"
75+
prop_headerConstructionWorks,
76+
testProperty
77+
"Footer construction works"
78+
prop_footerConstructionWorks
79+
],
7080
testGroup "Deserialisation" $
7181
[
7282
testProperty
@@ -353,6 +363,20 @@ prop_searchForUnmentionedKeyBeyondRangeWorks key (SearchableIndex index)
353363
selectionHead :: SerialisedKey
354364
selectionHead = head selection
355365

366+
-- ** Header and footer construction
367+
368+
prop_headerConstructionWorks :: Property
369+
prop_headerConstructionWorks
370+
= LazyByteString.unpack headerLBS
371+
===
372+
Primitive.toList testedTypeAndVersionBlock
373+
374+
prop_footerConstructionWorks :: NumEntries -> IndexOrdinary -> Property
375+
prop_footerConstructionWorks entryCount index
376+
= LazyByteString.unpack (finalLBS entryCount index)
377+
===
378+
Primitive.toList (entryCountBlock entryCount)
379+
356380
-- ** Deserialisation
357381

358382
prop_numberOfEntriesFromSerialisedIndexWorks :: NumEntries

0 commit comments

Comments
 (0)