@@ -0,0 +1,109 @@
2+-- Coverage build takes too long with default number of tests
11+allocOverhead = 2 * sizeOf (undefined :: Int)
13+-- XXX this should be in sync with the defaultChunkSize in Array code, or we
14+-- should expose that and use that. For fast testing we could reduce the
15+-- defaultChunkSize under CPP conditionals.
17+defaultChunkSize :: Int
18+defaultChunkSize = 32 * k - allocOverhead
22+maxArrLen = defaultChunkSize * 8
25+ (Int -> SerialT IO Int -> IO (Array Int))
27+genericTestFrom arrFold =
28+ forAll (choose (0, maxArrLen)) $ \len ->
29+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
31+ arr <- run $ arrFold len $ S.fromList list
32+ assert (A.length arr == len)
34+testLength :: Property
35+testLength = genericTestFrom (\n -> S.fold (A.writeN n))
37+testLengthFromStreamN :: Property
38+testLengthFromStreamN = genericTestFrom A.fromStreamN
41+ (Int -> SerialT IO Int -> IO (Array Int))
42+ -> (Array Int -> SerialT IO Int)
43+ -> ([Int] -> [Int] -> Bool)
45+genericTestFromTo arrFold arrUnfold listEq =
46+ forAll (choose (0, maxArrLen)) $ \len ->
47+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
49+ arr <- run $ arrFold len $ S.fromList list
50+ xs <- run $ S.toList $ arrUnfold arr
51+ assert (listEq xs list)
54+testFoldNUnfold :: Property
56+ genericTestFromTo (\n -> S.fold (A.writeN n)) (S.unfold A.read) (==)
58+testFoldNToStream :: Property
60+ genericTestFromTo (\n -> S.fold (A.writeN n)) A.toStream (==)
62+testFoldNToStreamRev :: Property
63+testFoldNToStreamRev =
65+ (\n -> S.fold (A.writeN n))
67+ (\xs list -> xs == reverse list)
69+testFromStreamNUnfold :: Property
70+testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
72+testFromStreamNToStream :: Property
73+testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
75+testFromListN :: Property
77+ forAll (choose (0, maxArrLen)) $ \len ->
78+ forAll (choose (0, len)) $ \n ->
79+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
81+ let arr = A.fromListN n list
82+ xs <- run $ S.toList $ (S.unfold A.read) arr
83+ listEquals (==) xs (take n list)
85+foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
87+ forAll (choose (0, maxArrLen)) $ \len ->
88+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
92+ $ S.unfoldMany A.read
97+commonMain :: SpecWith ()
99+ describe "Construction" $ do
100+ prop "length . writeN n === n" testLength
101+ prop "length . fromStreamN n === n" testLengthFromStreamN
102+ prop "read . writeN === id " testFoldNUnfold
103+ prop "toStream . writeN === id" testFoldNToStream
104+ prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
105+ prop "read . fromStreamN === id" testFromStreamNUnfold
106+ prop "toStream . fromStreamN === id" testFromStreamNToStream
107+ prop "fromListN" testFromListN
108+ prop "foldMany with writeN concats to original"
109+ (foldManyWith A.writeN)