@@ -109,9 +109,19 @@ $(Serialize.deriveSerializeWith
110 [d|instance Serialize a => Serialize (BinTree a)|])
110 [d|instance Serialize a => Serialize (BinTree a)|])
112+-- XXX This may not terminate, or could become really large.
112instance Arbitrary a => Arbitrary (BinTree a) where
113instance Arbitrary a => Arbitrary (BinTree a) where
113 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
114 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
116+-- Make a balanced tree of given level
117+mkBinTree :: (Arbitrary a) => Int -> IO (BinTree a)
118+mkBinTree = go (generate arbitrary)
123+ go r n = Tree <$> go r (n - 1) <*> go r (n - 1)
115--------------------------------------------------------------------------------
125--------------------------------------------------------------------------------
116-- Record syntax type
126-- Record syntax type
117--------------------------------------------------------------------------------
127--------------------------------------------------------------------------------
@@ -207,6 +217,10 @@ roundtrip
208roundtrip val = do
218roundtrip val = do
220+ -- For debugging large size generated by arbitrary
221+ -- let sz = Serialize.addSizeTo 0 val
222+ -- putStrLn $ "Size is: " ++ show sz
210 val `shouldBe` Array.deserialize (Array.pinnedSerialize val)
224 val `shouldBe` Array.deserialize (Array.pinnedSerialize val)
212 res <- poke val
226 res <- poke val
@@ -270,7 +284,12 @@ testCases = do
270 $ \(x :: [CustomDatatype]) -> roundtrip x
284 $ \(x :: [CustomDatatype]) -> roundtrip x
273− $ prop "BinTree" $ \(x :: BinTree Int) -> roundtrip x
287+ $ prop "BinTree"
288+ $ forAll (elements [1..15])
290+ (r :: BinTree Int) <- mkBinTree x