Sha256: d29eaf16b7c46bac85a327be1acb6a17d09e03ee0651276f8562f4f4c6ac394e

Contents?: true

Size: 1.63 KB

Versions: 13

Compression:

Stored size: 1.63 KB

Contents

{-# OPTIONS_GHC -fno-warn-type-defaults #-}

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

import Grains (square, total)

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

specs :: Spec
specs = describe "grains" $ do
          describe "square" $ for_ squareCases squareTest
          describe "total"  $ totalTest totalCase
  where

    squareTest (description, n, expected) = it description assertion
      where
        assertion  = expression `shouldBe` expected
        expression = fmap fromIntegral . square . fromIntegral $ n

    totalTest (description, expected) = it description assertion
      where
        assertion = fromIntegral total `shouldBe` expected

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

squareCases :: [(String, Integer, Maybe Integer)]
squareCases =
    [ ("square 1"             ,  1, Just                   1)
    , ("square 2"             ,  2, Just                   2)
    , ("square 3"             ,  3, Just                   4)
    , ("square 4"             ,  4, Just                   8)
    , ("square 16"            , 16, Just               32768)
    , ("square 32"            , 32, Just          2147483648)
    , ("square 64"            , 64, Just 9223372036854775808)
    , ("square negative"      , -1, Nothing                 )
    , ("square 0"             ,  0, Nothing                 )
    , ("square bigger than 64", 65, Nothing                 ) ]

totalCase :: (String, Integer)
totalCase = ("total grains", 18446744073709551615)

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
trackler-2.0.0.2 tracks/haskell/exercises/grains/test/Tests.hs
trackler-2.0.0.1 tracks/haskell/exercises/grains/test/Tests.hs
trackler-2.0.0.0 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.4.1 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.4.0 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.3.0 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.2.1 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.2.0 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.1.2 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.1.1 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.1.0 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.0.1 tracks/haskell/exercises/grains/test/Tests.hs
trackler-1.0.0 tracks/haskell/exercises/grains/test/Tests.hs