make Arbitrary POSIXTime include decimal half the time
This commit is contained in:
parent
2ca408dc33
commit
5ad5d45d4c
2 changed files with 11 additions and 13 deletions
|
@ -269,16 +269,8 @@ instance Arbitrary MTime where
|
|||
arbitrary = frequency
|
||||
-- timestamp is not usually negative
|
||||
[ (50, MTimeLowRes <$> (abs . fromInteger <$> arbitrary))
|
||||
, (50, MTimeHighRes <$> (abs <$> arbposixtime))
|
||||
, (50, MTimeHighRes <$> arbitrary)
|
||||
]
|
||||
where
|
||||
-- include fractional part, which the usual instance does not
|
||||
arbposixtime = do
|
||||
t <- arbitrary
|
||||
f <- arbitrary
|
||||
return $ if f == 0
|
||||
then t
|
||||
else t + recip f
|
||||
|
||||
#ifdef mingw32_HOST_OS
|
||||
instance Arbitrary FileID where
|
||||
|
|
|
@ -15,17 +15,23 @@ module Utility.QuickCheck
|
|||
|
||||
import Test.QuickCheck as X
|
||||
import Data.Time.Clock.POSIX
|
||||
import Data.Ratio
|
||||
import System.Posix.Types
|
||||
import Control.Applicative
|
||||
import Prelude
|
||||
|
||||
{- Times before the epoch are excluded, and no fraction is included. -}
|
||||
{- Times before the epoch are excluded. Half with decimal and half without. -}
|
||||
instance Arbitrary POSIXTime where
|
||||
arbitrary = fromInteger <$> nonNegative arbitrarySizedIntegral
|
||||
arbitrary = do
|
||||
n <- nonNegative arbitrarySizedBoundedIntegral :: Gen Int
|
||||
d <- nonNegative arbitrarySizedIntegral
|
||||
withd <- arbitrary
|
||||
return $ if withd
|
||||
then fromIntegral n + fromRational (1 % max d 1)
|
||||
else fromIntegral n
|
||||
|
||||
{- Pids are never negative, or 0. -}
|
||||
instance Arbitrary ProcessID where
|
||||
arbitrary = arbitrarySizedBoundedIntegral `suchThat` (> 0)
|
||||
arbitrary = positive arbitrarySizedBoundedIntegral
|
||||
|
||||
{- Inodes are never negative. -}
|
||||
instance Arbitrary FileID where
|
||||
|
|
Loading…
Reference in a new issue