Sha256: eb67d55f5ec196ce26ff2f0932afc91ea9a10ca908a4c1407080e7e5428c2962

Contents?: true

Size: 1.41 KB

Versions: 119

Compression:

Stored size: 1.41 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 LeapYear (isLeapYear)

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

specs :: Spec
specs = describe "isLeapYear" $ for_ cases test
  where

    test Case{..} = it explanation assertion
      where
        explanation = unwords [show input, "-", description]
        assertion   = isLeapYear (fromIntegral input) `shouldBe` expected

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

cases :: [Case]
cases = [ Case { description = "year not divisible by 4: common year"
               , input       = 2015
               , expected    = False
               }
        , Case { description = "year divisible by 4, not divisible by 100: leap year"
               , input       = 1996
               , expected    = True
               }
        , Case { description = "year divisible by 100, not divisible by 400: common year"
               , input       = 2100
               , expected    = False
               }
        , Case { description = "year divisible by 400: leap year"
               , input       = 2000
               , expected    = True
               }
        ]

Version data entries

119 entries across 119 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.158 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.157 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.156 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.155 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.154 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.153 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.152 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.151 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.150 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.149 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.148 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.147 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.146 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.145 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.144 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.143 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.142 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.141 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.140 tracks/haskell/exercises/leap/test/Tests.hs