2015-11-17 19:49:22 +00:00
|
|
|
{- quickcheck for scheduled activities
|
|
|
|
-
|
|
|
|
- Copyright 2013-2014 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- License: BSD-2-clause
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
|
2019-11-23 15:07:22 +00:00
|
|
|
module Utility.Scheduled.QuickCheck (prop_schedule_roundtrips) where
|
2015-11-17 19:49:22 +00:00
|
|
|
|
|
|
|
import Utility.Scheduled
|
|
|
|
import Utility.QuickCheck
|
|
|
|
|
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
|
|
|
|
|
|
|
instance Arbitrary Schedule where
|
|
|
|
arbitrary = Schedule <$> arbitrary <*> arbitrary
|
|
|
|
|
|
|
|
instance Arbitrary ScheduledTime where
|
|
|
|
arbitrary = oneof
|
|
|
|
[ pure AnyTime
|
|
|
|
, SpecificTime
|
|
|
|
<$> choose (0, 23)
|
|
|
|
<*> choose (1, 59)
|
|
|
|
]
|
|
|
|
|
2023-03-14 02:35:54 +00:00
|
|
|
instance Arbitrary Recurrence where
|
2015-11-17 19:49:22 +00:00
|
|
|
arbitrary = oneof
|
|
|
|
[ pure Daily
|
|
|
|
, Weekly <$> arbday
|
|
|
|
, Monthly <$> arbday
|
|
|
|
, Yearly <$> arbday
|
|
|
|
, Divisible
|
|
|
|
<$> positive arbitrary
|
|
|
|
<*> oneof -- no nested Divisibles
|
|
|
|
[ pure Daily
|
|
|
|
, Weekly <$> arbday
|
|
|
|
, Monthly <$> arbday
|
|
|
|
, Yearly <$> arbday
|
|
|
|
]
|
|
|
|
]
|
|
|
|
where
|
|
|
|
arbday = oneof
|
|
|
|
[ Just <$> nonNegative arbitrary
|
|
|
|
, pure Nothing
|
|
|
|
]
|
|
|
|
|
|
|
|
prop_schedule_roundtrips :: Schedule -> Bool
|
|
|
|
prop_schedule_roundtrips s = toSchedule (fromSchedule s) == Just s
|