2-- Coverage build takes too long with default number of tests
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.
17defaultChunkSize :: Int
18defaultChunkSize = 32 * k - allocOverhead
22maxArrLen = defaultChunkSize * 8
25 (Int -> SerialT IO Int -> IO (Array Int))
27genericTestFrom 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)
35testLength = genericTestFrom (S.fold . A.writeN)
37testLengthFromStreamN :: Property
38testLengthFromStreamN = genericTestFrom A.fromStreamN
41 (Int -> SerialT IO Int -> IO (Array Int))
42 -> (Array Int -> SerialT IO Int)
43 -> ([Int] -> [Int] -> Bool)
45genericTestFromTo 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)
54testFoldNUnfold :: Property
56 genericTestFromTo (S.fold . A.writeN) (S.unfold A.read) (==)
58testFoldNToStream :: Property
60 genericTestFromTo (S.fold . A.writeN) A.toStream (==)
62testFoldNToStreamRev :: Property
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
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)
85foldManyWith :: (Int -> Fold IO Int (Array Int)) -> Property
87 forAll (choose (0, maxArrLen)) $ \len ->
88 forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
97commonMain :: 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)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list