Skip to content

Commit

Permalink
fixup! Test and benchmark for date field check
Browse files Browse the repository at this point in the history
  • Loading branch information
olorin committed Jul 19, 2016
1 parent 9fa8b76 commit 070395b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions test/Test/Warden/Arbitrary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -805,9 +805,27 @@ genSensibleDateTime = do
secs <- secondsToDiffTime <$> choose (0, 86401)
pure $ UTCTime days secs

genSillyDateTime :: Gen UTCTime
genSillyDateTime = do
days <- oneof [
whenIWasALad
, hurdReleaseDate
]
secs <- secondsToDiffTime <$> choose (0, 86401)
pure $ UTCTime days secs
where
-- Uniform between 0001-01-01 and 1858-11-17
whenIWasALad = ModifiedJulianDay <$> choose ((- 678575), 0)

-- Uniform between 4616-10-14 and 2739765-11-19.
hurdReleaseDate = ModifiedJulianDay <$> choose (100000, 100000000)

renderedDate :: Gen BS.ByteString
renderedDate = do
dt <- genSensibleDateTime
renderedDate = renderedDate' genSensibleDateTime

renderedDate' :: Gen UTCTime -> Gen BS.ByteString
renderedDate' gdt = do
dt <- gdt
render <- frequency [(1, renderDateNoSeparator), (9, renderDateSeparator)]
pure . BSC.pack $ render dt

Expand Down Expand Up @@ -839,14 +857,9 @@ renderedNonDate = do
dt <- renderedDate
oneof [
pure $ x <> dt
, reversed
, renderedDate' genSillyDateTime
, encodeUtf8 <$> elements muppets
]
where
reversed = do
dt <- genSensibleDateTime
render <- renderDateSeparator
pure . BSC.pack . reverse $ render dt

noDigits =
elements $ [0x00..0xff] \\ [0x30..0x39]

0 comments on commit 070395b

Please sign in to comment.