Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate interesting Days and UniversalTimes #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Test/QuickCheck/Instances.hs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ instance Arbitrary1 Tree.Tree where
rest <- arbPartition $ k - first
return $ first : rest

liftShrink shr = go
liftShrink shr = go
where
go (Tree.Node val forest) = forest ++
[ Tree.Node e fs
Expand Down Expand Up @@ -352,7 +352,10 @@ instance CoArbitrary OldTime.CalendarTime where
-------------------------------------------------------------------------------

instance Arbitrary Time.Day where
arbitrary = Time.ModifiedJulianDay <$> (2000 +) <$> arbitrary
arbitrary = sized $ \n -> do
let limit = (toInteger n)*365
Copy link
Collaborator

@phadej phadej Jan 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n can be big, say 10000, is it ok here? (even 1000 feels fishy...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There doesn't seem to be any inherent problem with such large values:

λ ModifiedJulianDay $ -10000*365
-8135-07-08
λ ModifiedJulianDay $ 10000*365
11852-03-28
λ UTCTime (ModifiedJulianDay $ -10000*365) 0
-8135-07-08 00:00:00 UTC

offset <- choose (-limit, limit)
return $ Time.addDays offset (Time.fromGregorian 2000 1 1)
shrink = (Time.ModifiedJulianDay <$>) . shrink . Time.toModifiedJulianDay

instance CoArbitrary Time.Day where
Expand All @@ -362,7 +365,10 @@ instance Function Time.Day where
function = functionMap Time.toModifiedJulianDay Time.ModifiedJulianDay

instance Arbitrary Time.UniversalTime where
arbitrary = Time.ModJulianDate <$> (2000 +) <$> arbitrary
arbitrary = sized $ \n -> do
let limit = (fromIntegral n)*365.25 :: Double
offset <- toRational <$> choose (-limit, limit)
return $ Time.ModJulianDate $ toRational (Time.toModifiedJulianDay (Time.fromGregorian 2000 1 1)) + offset
shrink = (Time.ModJulianDate <$>) . shrink . Time.getModJulianDate

instance CoArbitrary Time.UniversalTime where
Expand Down