1module Test.Calendar.AddDays(addDaysTest) where
2
3import Data.Time.Calendar.Compat
4
5import Test.Tasty
6import Test.Tasty.HUnit
7import Test.Calendar.AddDaysRef
8
9days ::[Day]
10days =
11    [
12    fromGregorian 2005 2 28,
13    fromGregorian 2004 2 29,
14    fromGregorian 2004 1 31,
15    fromGregorian 2004 12 31,
16    fromGregorian 2005 7 1,
17    fromGregorian 2005 4 21,
18    fromGregorian 2005 6 30
19    ]
20
21increments :: [Integer]
22increments = [-10,-4,-1,0,1,7,83]
23
24adders :: [(String,Integer -> Day -> Day)]
25adders =
26    [
27    ("day",addDays),
28    ("month (clip)",addGregorianMonthsClip),
29    ("month (roll over)",addGregorianMonthsRollOver),
30    ("year (clip)",addGregorianYearsClip),
31    ("year (roll over)",addGregorianYearsRollOver)
32    ]
33
34resultDays :: [String]
35resultDays = do
36    (aname,adder) <- adders
37    increment <- increments
38    day <- days
39    return ((showGregorian day) ++ " + " ++ (show increment) ++ " * " ++ aname ++ " = " ++ showGregorian (adder increment day))
40
41addDaysTest :: TestTree
42addDaysTest = testCase "addDays" $
43    assertEqual "" addDaysRef $ unlines resultDays
44