on 08046ff help sign in
109 lines 3.6 kB history raw
2-- Coverage build takes too long with default number of tests
3maxTestCount :: Int
4#ifdef DEVBUILD
5maxTestCount = 100
6#else
7maxTestCount = 10
8#endif
10allocOverhead :: Int
11allocOverhead = 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.
16--
17defaultChunkSize :: Int
18defaultChunkSize = 32 * k - allocOverhead
19 where k = 1024
21maxArrLen :: Int
22maxArrLen = defaultChunkSize * 8
24genericTestFrom ::
25 (Int -> SerialT IO Int -> IO (Array Int))
26 -> Property
27genericTestFrom arrFold =
28 forAll (choose (0, maxArrLen)) $ \len ->
29 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
30 monadicIO $ do
31 arr <- run $ arrFold len $ S.fromList list
32 assert (A.length arr == len)
34testLength :: Property
35testLength = genericTestFrom (S.fold . A.writeN)
37testLengthFromStreamN :: Property
38testLengthFromStreamN = genericTestFrom A.fromStreamN
40genericTestFromTo ::
41 (Int -> SerialT IO Int -> IO (Array Int))
42 -> (Array Int -> SerialT IO Int)
43 -> ([Int] -> [Int] -> Bool)
44 -> Property
45genericTestFromTo arrFold arrUnfold listEq =
46 forAll (choose (0, maxArrLen)) $ \len ->
47 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
48 monadicIO $ do
49 arr <- run $ arrFold len $ S.fromList list
50 xs <- run $ S.toList $ arrUnfold arr
51 assert (listEq xs list)
54testFoldNUnfold :: Property
55testFoldNUnfold =
56 genericTestFromTo (S.fold . A.writeN) (S.unfold A.read) (==)
58testFoldNToStream :: Property
59testFoldNToStream =
60 genericTestFromTo (S.fold . A.writeN) A.toStream (==)
62testFoldNToStreamRev :: Property
63testFoldNToStreamRev =
64 genericTestFromTo
65 (S.fold . A.writeN)
66 A.toStreamRev
67 (\xs list -> xs == reverse list)
69testFromStreamNUnfold :: Property
70testFromStreamNUnfold = genericTestFromTo A.fromStreamN (S.unfold A.read) (==)
72testFromStreamNToStream :: Property
73testFromStreamNToStream = genericTestFromTo A.fromStreamN A.toStream (==)
75testFromListN :: Property
76testFromListN =
77 forAll (choose (0, maxArrLen)) $ \len ->
78 forAll (choose (0, len)) $ \n ->
79 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
80 monadicIO $ do
81 let arr = A.fromListN n list
82 xs <- run $ S.toList $ S.unfold A.read arr
83 listEquals (==) xs (take n list)
85foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
86foldManyWith f =
87 forAll (choose (0, maxArrLen)) $ \len ->
88 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
89 monadicIO $ do
90 xs <- run
91 $ S.toList
92 $ S.unfoldMany A.read
93 $ S.foldMany (f 240)
94 $ S.fromList list
95 assert (xs == list)
97commonMain :: SpecWith ()
98commonMain = do
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)