@@ -109,9 +109,19 @@ $(Serialize.deriveSerializeWith
109109 CONF
110110 [d|instance Serialize a => Serialize (BinTree a)|])
111111
112+-- XXX This may not terminate, or could become really large.
112113instance Arbitrary a => Arbitrary (BinTree a) where
113114 arbitrary = oneof [Leaf <$> arbitrary, Tree <$> arbitrary <*> arbitrary]
114115
116+-- Make a balanced tree of given level
117+mkBinTree :: (Arbitrary a) => Int -> IO (BinTree a)
118+mkBinTree = go (generate arbitrary)
119+
120+ where
121+
122+ go r 0 = Leaf <$> r
123+ go r n = Tree <$> go r (n - 1) <*> go r (n - 1)
124+
115125--------------------------------------------------------------------------------
116126-- Record syntax type
117127--------------------------------------------------------------------------------
@@ -207,6 +217,10 @@ roundtrip
207217 -> IO ()
208218roundtrip val = do
209219
220+ -- For debugging large size generated by arbitrary
221+ -- let sz = Serialize.addSizeTo 0 val
222+ -- putStrLn $ "Size is: " ++ show sz
223+
210224 val `shouldBe` Array.deserialize (Array.pinnedSerialize val)
211225
212226 res <- poke val
@@ -270,7 +284,12 @@ testCases = do
270284 $ \(x :: [CustomDatatype]) -> roundtrip x
271285
272286 limitQC
273− $ prop "BinTree" $ \(x :: BinTree Int) -> roundtrip x
287+ $ prop "BinTree"
288+ $ forAll (elements [1..15])
289+ (\(x :: Int) -> do
290+ (r :: BinTree Int) <- mkBinTree x
291+ roundtrip r
292+ )
274293
275294 where
276295