Sha256: fb29501a63aee181fedc9e656f84c67586971e76fd2e669a24273afccd5d52b2

Contents?: true

Size: 1.1 KB

Versions: 229

Compression:

Stored size: 1.1 KB

Contents

import Data.Char         (toUpper)
import Test.Hspec        (Spec, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import Accumulate (accumulate)

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

specs :: Spec
specs = do

    let square x = x * x :: Int

    it "empty accumulation" $
      accumulate square []
      `shouldBe` []

    it "accumulate squares" $
      accumulate square [1, 2, 3]
      `shouldBe` [1, 4, 9]

    it "accumulate upcases" $
      accumulate (map toUpper) ["hello", "world"]
      `shouldBe` ["HELLO", "WORLD"]

    it "accumulate reversed strings" $
      accumulate reverse ["the", "quick", "brown", "fox", "etc"]
      `shouldBe` ["eht", "kciuq", "nworb", "xof", "cte"]

    it "accumulate recursively" $
      accumulate (\c -> accumulate ((c:) . show) ([1, 2, 3] :: [Int])) "abc"
      `shouldBe` [["a1", "a2", "a3"], ["b1", "b2", "b3"], ["c1", "c2", "c3"]]

    it "accumulate non-strict" $
      take 1 (accumulate id ("nice work!" : error "accumulate should be even lazier, don't use reverse!"))
      `shouldBe` ["nice work!"]

Version data entries

229 entries across 229 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.118 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.117 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.116 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.115 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.114 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.113 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.111 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.110 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.109 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.108 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.107 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.106 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.105 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.104 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.103 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.102 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.101 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.100 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.2.1.99 tracks/haskell/exercises/accumulate/test/Tests.hs