From 070395b3258c58ec7eb8af38d5f22ab63a2244d4 Mon Sep 17 00:00:00 2001 From: Sharif Olorin Date: Tue, 19 Jul 2016 01:27:57 +0000 Subject: [PATCH] fixup! Test and benchmark for date field check --- test/Test/Warden/Arbitrary.hs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/test/Test/Warden/Arbitrary.hs b/test/Test/Warden/Arbitrary.hs index 432a265..bad50e4 100644 --- a/test/Test/Warden/Arbitrary.hs +++ b/test/Test/Warden/Arbitrary.hs @@ -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 @@ -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]