on master help sign in
Add more tests for Prelude operations
commit70a56d13e46ca3df8c56d87a4e860acc1243f155 authorHarendra Kumar <harendra.kumar@gmail.com> dateSun 11 Mar 2018, 02:36 (9 years ago) parent8e4a60c
1 file changed+33−8
test/Main.hs+33−8
test/Main.hs+33−8
@@ -638,32 +638,57 @@ streamOperations :: Streaming t => (t IO Int, [Int], Int) -> Spec
638638streamOperations (stream, list, len) = do
639639
640640 -- Filtering
641+ it "filter all out" $ transform (A.filter (> len)) (filter (> len))
642+ it "filter all in" $ transform (A.filter (<= len)) (filter (<= len))
643+ it "filter even" $ transform (A.filter even) (filter even)
644+
641645 it "take all" $ transform (A.take len) (take len)
642646 it "take none" $ transform (A.take 0) (take 0)
643647 it "take some" $ transform (A.take $ len - 1) (take $ len - 1)
644648 it "take one" $ transform (A.take 1) (take 1)
645649
650+ it "takeWhile true" $ transform (A.takeWhile (const True))
651+ (takeWhile (const True))
652+ it "takeWhile false" $ transform (A.takeWhile (const False))
653+ (takeWhile (const False))
654+ it "takeWhile < some" $ transform (A.takeWhile (< (len `div` 2)))
655+ (takeWhile (< (len `div` 2)))
656+
646657 it "drop all" $ transform (A.drop len) (drop len)
647658 it "drop none" $ transform (A.drop 0) (drop 0)
648659 it "drop some" $ transform (A.drop $ len - 1) (drop $ len - 1)
649660 it "drop one" $ transform (A.drop 1) (drop 1)
650661
651662 it "dropWhile true" $ transform (A.dropWhile (const True))
652− (dropWhile (const True))
663+ (dropWhile (const True))
653664 it "dropWhile false" $ transform (A.dropWhile (const False))
654− (dropWhile (const False))
665+ (dropWhile (const False))
655666 it "dropWhile < some" $ transform (A.dropWhile (< (len `div` 2)))
656667 (dropWhile (< (len `div` 2)))
657668
658− it "filter all out" $ transform (A.filter (> len)) (filter (> len))
659− it "filter all in" $ transform (A.filter (<= len)) (filter (<= len))
660− it "filter even" $ transform (A.filter even) (filter even)
661−
662669 -- Elimination
663670 it "foldl" $ elimination (A.foldl (+) 0 id) (foldl (+) 0)
671+ it "all" $ elimination (A.all even) (all even)
672+ it "any" $ elimination (A.any even) (any even)
673+ it "length" $ elimination A.length length
674+ it "elem" $ elimination (A.elem (len - 1)) (elem (len - 1))
675+ it "elem" $ elimination (A.elem (len + 1)) (elem (len + 1))
676+ it "notElem" $ elimination (A.notElem (len - 1)) (notElem (len - 1))
677+ it "notElem" $ elimination (A.notElem (len + 1)) (notElem (len + 1))
678+ it "sum" $ elimination A.sum sum
679+ it "product" $ elimination A.product product
680+
664681 if list == []
665− then it "last empty" $ A.last stream `shouldReturn` Nothing
666− else it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
682+ then do
683+ it "head empty" $ A.head stream `shouldReturn` Nothing
684+ it "last empty" $ A.last stream `shouldReturn` Nothing
685+ it "maximum empty" $ A.maximum stream `shouldReturn` Nothing
686+ it "minimum empty" $ A.minimum stream `shouldReturn` Nothing
687+ else do
688+ it "head nonEmpty" $ A.head stream `shouldReturn` Just (head list)
689+ it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
690+ it "maximum nonEmpty" $ A.maximum stream `shouldReturn` Just (maximum list)
691+ it "minimum nonEmpty" $ A.minimum stream `shouldReturn` Just (minimum list)
667692
668693 where
669694