Sha256: 570dd3bf3129fc6f831872a35e5f2037589fc4716f42366a710393543cbd5625

Contents?: true

Size: 2 KB

Versions: 165

Compression:

Stored size: 2 KB

Contents

import Test.Hspec        (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import Data.List (isPrefixOf)

import Strain (discard, keep)

main :: IO ()
main = hspecWith defaultConfig {configFastFail = True} specs

specs :: Spec
specs = describe "strain" $ do

    -- As of 2016-07-27, there was no reference file
    -- for the test cases in `exercism/x-common`.

    it "empty keep" $
        keep (<10) [] `shouldBe` ([] :: [Int])

    it "keep everything" $
        keep (<10) [1, 2, 3] `shouldBe` [1, 2, 3 :: Int]

    it "keep first and last" $
        keep odd [1, 2, 3] `shouldBe` [1, 3 :: Int]

    it "keep nothing" $
        keep even [1, 3, 5, 7] `shouldBe` ([] :: [Int])

    it "keep neither first nor last" $
        keep even [1, 2, 3] `shouldBe` [2 :: Int]

    it "keep strings" $
        keep ("z" `isPrefixOf`)
        ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"]
        `shouldBe`
        ["zebra", "zombies", "zealot"]

    it "empty discard" $
        discard (< 10) [] `shouldBe` ([] :: [Int])

    it "discard everything" $
        discard (< 10) [1, 2, 3] `shouldBe` ([] :: [Int])

    it "discard first and last" $
        discard odd [1, 2, 3] `shouldBe` [2 :: Int]

    it "discard nothing" $
        discard even [1, 3, 5, 7] `shouldBe` [1, 3, 5, 7 :: Int]

    it "discard neither first nor last" $
        discard even [1, 2, 3] `shouldBe` [1, 3 :: Int]

    it "discard strings" $
        discard ("z" `isPrefixOf`)
        ["apple", "zebra", "banana", "zombies", "cherimoya", "zealot"]
        `shouldBe`
        ["apple", "banana", "cherimoya"]

    it "keep non-strict" $
        (take 1 . keep (const True))
        ("yes" : error "keep should be lazier - don't look at list elements you don't need!")
        `shouldBe`
        ["yes"]

    it "discard non-strict" $
        (take 1 . discard (const False))
        ("yes" : error "discard should be lazier - don't look at list elements you don't need!")
        `shouldBe`
        ["yes"]

Version data entries

165 entries across 165 versions & 1 rubygems

Version Path
trackler-2.0.8.45 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.44 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.43 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.42 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.41 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.40 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.39 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.38 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.37 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.36 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.35 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.34 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.33 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.32 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.31 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.30 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.29 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.28 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.27 tracks/haskell/exercises/strain/test/Tests.hs
trackler-2.0.8.26 tracks/haskell/exercises/strain/test/Tests.hs