Sha256: fd6a054a20da8feae333b0b9ad824778736d987a52465a88dcc77840755b9184

Contents?: true

Size: 1.41 KB

Versions: 96

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       = 2016
               , 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

96 entries across 96 versions & 1 rubygems

Version Path
trackler-2.2.1.45 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.44 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.43 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.42 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.41 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.40 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.39 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.38 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.37 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.36 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.35 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.34 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.33 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.32 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.31 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.30 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.29 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.28 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.27 tracks/haskell/exercises/leap/test/Tests.hs
trackler-2.2.1.26 tracks/haskell/exercises/leap/test/Tests.hs