Sha256: f476c0039e8d25e331664af86b365cc8e45ae8a59f0abeec44de17c116c057c9

Contents?: true

Size: 1.24 KB

Versions: 165

Compression:

Stored size: 1.24 KB

Contents

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

import Accumulate (accumulate)

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

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

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

    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

165 entries across 165 versions & 1 rubygems

Version Path
trackler-2.0.8.4 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.8.3 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.8.2 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.8.1 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.7.0 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.44 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.43 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.42 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.41 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.40 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.39 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.38 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.37 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.36 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.35 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.34 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.33 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.32 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.31 tracks/haskell/exercises/accumulate/test/Tests.hs
trackler-2.0.6.30 tracks/haskell/exercises/accumulate/test/Tests.hs