on master help sign in
Modify boundary condition tests for lastN
9fd164badithyaov
test/Streamly/Test/Array.hs+12−18
@@ -150,21 +150,12 @@ testLastN =
150 $ S.fromList list
150 $ S.fromList list
151 assert (xs == lastN n list)
151 assert (xs == lastN n list)
152
152
153−testLastNLT :: Property
153+testLastN_LN :: Int -> Int -> IO Bool
154−testLastNLT =
154+testLastN_LN len n = do
155− forAll (choose (0, maxArrLen)) $ \len ->
155+ let list = [1..len]
156− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
157− monadicIO $ do
158− xs <- fmap A.toList $ S.fold (A.lastN 0) $ S.fromList list
156+ l1 <- fmap A.toList $ S.fold (A.lastN n) $ S.fromList list
159− assert (xs == lastN 0 list)
157+ let l2 = lastN n list
160−
158+ return $ l1 == l2
161−testLastNGT :: Property
162−testLastNGT =
163− forAll (choose (0, maxArrLen)) $ \len ->
164− forAll (vectorOf len (arbitrary :: Gen Int)) $ \list ->
165− monadicIO $ do
166− xs <- fmap A.toList $ S.fold (A.lastN (len + 1)) $ S.fromList list
167− assert (xs == lastN (len + 1) list)
168#endif
159#endif
169
160
170main :: IO ()
161main :: IO ()
@@ -190,7 +181,10 @@ main =
190#endif
181#endif
191#ifdef TEST_ARRAY
182#ifdef TEST_ARRAY
192 describe "Fold" $ do
183 describe "Fold" $ do
193− prop "lastN : 0 <= n < len" $ testLastN
184+ prop "lastN : 0 <= n <= len" $ testLastN
194− prop "lastN : n = 0" $ testLastNLT
185+ describe "lastN boundary conditions" $ do
195− prop "lastN : n = len + 1" $ testLastNGT
186+ it "lastN -1" (testLastN_LN 10 (-1) `shouldReturn` True)
187+ it "lastN 0" (testLastN_LN 10 0 `shouldReturn` True)
188+ it "lastN length" (testLastN_LN 10 10 `shouldReturn` True)
189+ it "lastN (length + 1)" (testLastN_LN 10 11 `shouldReturn` True)
196#endif
190#endif