@@ -132,26 +132,44 @@ testArraysOf =
132132 $ IP.arraysOf 240
133133 $ S.fromList list
134134 assert (xs == list)
135+
136+lastN :: Int -> [a] -> [a]
137+lastN n l = drop (length l - n) l
138+
139+testLastN :: Property
140+testLastN =
141+ forAll (choose (0, maxArrLen)) $ \len ->
142+ forAll (choose (0, len)) $ \n ->
143+ forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
144+ monadicIO $ do
145+ xs <- fmap A.toList
146+ $ S.fold (A.lastN n)
147+ $ S.fromList list
148+ assert (xs == lastN n list)
135149#endif
136150
137151main :: IO ()
138152main =
139153 hspec $
140154 H.parallel $
141− modifyMaxSuccess (const maxTestCount) $
142− describe "Construction" $ do
143− prop "length . writeN n === n" testLength
144− prop "length . fromStreamN n === n" testLengthFromStreamN
145− prop "read . writeN === id " testFoldNUnfold
146− prop "toStream . writeN === id" testFoldNToStream
147− prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
148− prop "read . fromStreamN === id" testFromStreamNUnfold
149− prop "toStream . fromStreamN === id" testFromStreamNToStream
155+ modifyMaxSuccess (const maxTestCount) $ do
156+ describe "Construction" $ do
157+ prop "length . writeN n === n" testLength
158+ prop "length . fromStreamN n === n" testLengthFromStreamN
159+ prop "read . writeN === id " testFoldNUnfold
160+ prop "toStream . writeN === id" testFoldNToStream
161+ prop "toStreamRev . writeN === reverse" testFoldNToStreamRev
162+ prop "read . fromStreamN === id" testFromStreamNUnfold
163+ prop "toStream . fromStreamN === id" testFromStreamNToStream
150164#ifndef TEST_SMALL_ARRAY
151− prop "length . fromStream === n" testLengthFromStream
152− prop "toStream . fromStream === id" testFromStreamToStream
153− prop "read . write === id" testFoldUnfold
165+ prop "length . fromStream === n" testLengthFromStream
166+ prop "toStream . fromStream === id" testFromStreamToStream
167+ prop "read . write === id" testFoldUnfold
168+#endif
169+#ifdef TEST_ARRAY
170+ prop "arraysOf concats to original" testArraysOf
154171#endif
155172#ifdef TEST_ARRAY
156− prop "arraysOf concats to original" testArraysOf
173+ describe "Fold" $ do
174+ prop "lastN" $ testLastN
157175#endif