packages feed

holidays-0.4.0.0: tst/Test/Holidays.hs

module Test.Holidays (
  countryPropTests,
  day,
) where

import qualified Data.Set as S
import Data.Time
import qualified Holidays as H
import Test.Tasty
import Test.Tasty.QuickCheck as QC

day :: Year -> MonthOfYear -> DayOfMonth -> Day
day = fromGregorian

countryPropTests :: H.ISO_3166_1_Alpha_3 -> TestTree
countryPropTests countryCode =
  let uniqueYears c y =
        S.map
          ( \h ->
              let
                (year', _, _) = toGregorian (H.holidayValue h)
              in
                year'
          )
          (H.holidays c y)
  in  testGroup
        ("Holidays property based tests for country " <> show countryCode)
        [ QC.testProperty "Day always in the same year" $
            \year -> S.singleton year == uniqueYears countryCode year
        ]