Sha256: 582e5213e37de604b58b117b186ce63e1bce7e9a670a523df28115369fb8acfa

Contents?: true

Size: 1.35 KB

Versions: 229

Compression:

Stored size: 1.35 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" $ for_ cases test
  where

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

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

229 entries across 229 versions & 1 rubygems

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