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