Skip to content

Commit 4f60acd

Browse files
committed
SUGGESTION: test that conversion to/from unsliced keys preserves Eq/Ord
1 parent 72ad78f commit 4f60acd

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

lsm-tree.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ test-suite lsm-tree-test
390390
Test.Database.LSMTree.Internal.Snapshot.Codec
391391
Test.Database.LSMTree.Internal.Snapshot.Codec.Golden
392392
Test.Database.LSMTree.Internal.Snapshot.FS
393+
Test.Database.LSMTree.Internal.Unsliced
393394
Test.Database.LSMTree.Internal.Vector
394395
Test.Database.LSMTree.Internal.Vector.Growing
395396
Test.Database.LSMTree.Internal.WriteBufferBlobs.FS

test/Main.hs

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import qualified Test.Database.LSMTree.Internal.Serialise.Class
3535
import qualified Test.Database.LSMTree.Internal.Snapshot.Codec
3636
import qualified Test.Database.LSMTree.Internal.Snapshot.Codec.Golden
3737
import qualified Test.Database.LSMTree.Internal.Snapshot.FS
38+
import qualified Test.Database.LSMTree.Internal.Unsliced
3839
import qualified Test.Database.LSMTree.Internal.Vector
3940
import qualified Test.Database.LSMTree.Internal.Vector.Growing
4041
import qualified Test.Database.LSMTree.Internal.WriteBufferBlobs.FS
@@ -82,6 +83,7 @@ main = do
8283
, Test.Database.LSMTree.Internal.Snapshot.Codec.tests
8384
, Test.Database.LSMTree.Internal.Snapshot.Codec.Golden.tests
8485
, Test.Database.LSMTree.Internal.Snapshot.FS.tests
86+
, Test.Database.LSMTree.Internal.Unsliced.tests
8587
, Test.Database.LSMTree.Internal.Vector.tests
8688
, Test.Database.LSMTree.Internal.Vector.Growing.tests
8789
, Test.Database.LSMTree.Internal.WriteBufferBlobs.FS.tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Test.Database.LSMTree.Internal.Unsliced (tests) where
2+
3+
import Database.LSMTree.Extras.Generators ()
4+
import Database.LSMTree.Internal.Serialise
5+
import Database.LSMTree.Internal.Unsliced
6+
import Test.Tasty
7+
import Test.Tasty.QuickCheck
8+
9+
tests :: TestTree
10+
tests = testGroup "Test.Database.LSMTree.Internal.Unsliced" [
11+
testProperty "prop_makeUnslicedKeyPreservesEq" prop_makeUnslicedKeyPreservesEq
12+
, testProperty "prop_fromUnslicedKeyPreservesEq" prop_fromUnslicedKeyPreservesEq
13+
, testProperty "prop_makeUnslicedKeyPreservesOrd" prop_makeUnslicedKeyPreservesOrd
14+
, testProperty "prop_fromUnslicedKeyPreservesOrd" prop_fromUnslicedKeyPreservesOrd
15+
]
16+
17+
-- 'Eq' on serialised keys is preserved when converting to /unsliced/ serialised
18+
-- keys.
19+
prop_makeUnslicedKeyPreservesEq :: SerialisedKey -> SerialisedKey -> Property
20+
prop_makeUnslicedKeyPreservesEq k1 k2 = checkCoverage $
21+
cover 1 lhs "k1 == k2" $ lhs === rhs
22+
where
23+
lhs = k1 == k2
24+
rhs = makeUnslicedKey k1 == makeUnslicedKey k2
25+
26+
-- 'Eq' on /unsliced/ serialised keys is preserved when converting to serialised
27+
-- keys.
28+
prop_fromUnslicedKeyPreservesEq :: Unsliced SerialisedKey -> Unsliced SerialisedKey -> Property
29+
prop_fromUnslicedKeyPreservesEq k1 k2 = checkCoverage $
30+
cover 1 lhs "k1 == k2" $ lhs === rhs
31+
where
32+
lhs = k1 == k2
33+
rhs = fromUnslicedKey k1 == fromUnslicedKey k2
34+
35+
-- 'Ord' on serialised keys is preserved when converting to /unsliced/
36+
-- serialised keys.
37+
prop_makeUnslicedKeyPreservesOrd :: SerialisedKey -> SerialisedKey -> Property
38+
prop_makeUnslicedKeyPreservesOrd k1 k2 = checkCoverage $
39+
cover 50 lhs "k1 <= k2" $ lhs === rhs
40+
where
41+
lhs = k1 <= k2
42+
rhs = makeUnslicedKey k1 <= makeUnslicedKey k2
43+
44+
-- 'Ord' on /unsliced/ serialised keys is preserved when converting to serialised
45+
-- keys.
46+
prop_fromUnslicedKeyPreservesOrd :: Unsliced SerialisedKey -> Unsliced SerialisedKey -> Property
47+
prop_fromUnslicedKeyPreservesOrd k1 k2 = checkCoverage $
48+
cover 50 lhs "k1 <= k2" $ lhs === rhs
49+
where
50+
lhs = k1 <= k2
51+
rhs = fromUnslicedKey k1 <= fromUnslicedKey k2

0 commit comments

Comments
 (0)