Sha256: 112201d592a78da9367ae0a5869aeaa9ebb06ea64d278ec5c3fcab0b9b9be300

Contents?: true

Size: 1.44 KB

Versions: 165

Compression:

Stored size: 1.44 KB

Contents

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

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

import Prime (nth)

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

specs :: Spec
specs = describe "nth-prime" $
          describe "nth" $ for_ cases test
  where

    test Case{..} = it description assertion
      where
        assertion = nth (fromIntegral input) `shouldBe` expected

-- Test cases adapted from `exercism/x-common` on 2016-09-19.

data Case = Case { description :: String
                 , input       :: Integer
                 , expected    :: Maybe Integer
                 }

cases :: [Case]
cases = [ Case { description = "first prime"
               , input       = 1
               , expected    = Just 2
               }
        , Case { description = "second prime"
               , input       = 2
               , expected    = Just 3
               }
        , Case { description = "sixth prime"
               , input       = 6
               , expected    = Just 13
               }
        , Case { description = "big prime"
               , input       = 10001
               , expected    = Just 104743
               }
        , Case { description = "there is no zeroth prime"
               , input       = 0
               , expected    = Nothing
               }
        ]

Version data entries

165 entries across 165 versions & 1 rubygems

Version Path
trackler-2.1.0.9 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.8 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.7 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.6 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.5 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.4 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.3 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.2 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.1 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.1.0.0 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.55 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.54 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.53 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.52 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.51 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.50 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.49 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.48 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.47 tracks/haskell/exercises/nth-prime/test/Tests.hs
trackler-2.0.8.46 tracks/haskell/exercises/nth-prime/test/Tests.hs