{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Test.QuickCheck.Instances.OldTime () where
import Prelude ()
import Test.QuickCheck.Instances.CustomPrelude
import Data.Int (Int32)
import Test.QuickCheck
import qualified System.Time as OldTime
instance Arbitrary OldTime.Month where
arbitrary :: Gen Month
arbitrary = Gen Month
forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum
instance CoArbitrary OldTime.Month where
coarbitrary :: Month -> Gen b -> Gen b
coarbitrary = Month -> Gen b -> Gen b
forall a b. Enum a => a -> Gen b -> Gen b
coarbitraryEnum
instance Arbitrary OldTime.Day where
arbitrary :: Gen Day
arbitrary = Gen Day
forall a. (Bounded a, Enum a) => Gen a
arbitraryBoundedEnum
instance CoArbitrary OldTime.Day where
coarbitrary :: Day -> Gen b -> Gen b
coarbitrary = Day -> Gen b -> Gen b
forall a b. Enum a => a -> Gen b -> Gen b
coarbitraryEnum
instance Arbitrary OldTime.ClockTime where
arbitrary :: Gen ClockTime
arbitrary =
Integer -> Integer -> ClockTime
OldTime.TOD (Integer -> Integer -> ClockTime)
-> Gen Integer -> Gen (Integer -> ClockTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (Integer
0, Int32 -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int32
forall a. Bounded a => a
maxBound :: Int32))
Gen (Integer -> ClockTime) -> Gen Integer -> Gen ClockTime
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Integer, Integer) -> Gen Integer
forall a. Random a => (a, a) -> Gen a
choose (Integer
0, Integer
1000000000000 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
1)
shrink :: ClockTime -> [ClockTime]
shrink (OldTime.TOD Integer
s Integer
p) =
[ Integer -> Integer -> ClockTime
OldTime.TOD Integer
s' Integer
p | Integer
s' <- Integer -> [Integer]
forall a. Arbitrary a => a -> [a]
shrink Integer
s ] [ClockTime] -> [ClockTime] -> [ClockTime]
forall a. [a] -> [a] -> [a]
++
[ Integer -> Integer -> ClockTime
OldTime.TOD Integer
s Integer
p' | Integer
p' <- Integer -> [Integer]
forall a. Arbitrary a => a -> [a]
shrink Integer
p ]
instance CoArbitrary OldTime.ClockTime where
coarbitrary :: ClockTime -> Gen b -> Gen b
coarbitrary (OldTime.TOD Integer
s Integer
p) =
Integer -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Integer
s (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Integer
p
instance Arbitrary OldTime.TimeDiff where
arbitrary :: Gen TimeDiff
arbitrary =
TimeDiff -> TimeDiff
OldTime.normalizeTimeDiff (TimeDiff -> TimeDiff) -> Gen TimeDiff -> Gen TimeDiff
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(ClockTime -> ClockTime -> TimeDiff
OldTime.diffClockTimes (ClockTime -> ClockTime -> TimeDiff)
-> Gen ClockTime -> Gen (ClockTime -> TimeDiff)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ClockTime
forall a. Arbitrary a => Gen a
arbitrary Gen (ClockTime -> TimeDiff) -> Gen ClockTime -> Gen TimeDiff
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen ClockTime
forall a. Arbitrary a => Gen a
arbitrary)
shrink :: TimeDiff -> [TimeDiff]
shrink td :: TimeDiff
td@(OldTime.TimeDiff Int
year Int
month Int
day Int
hour Int
minute Int
sec Integer
picosec) =
[ TimeDiff
td { tdYear :: Int
OldTime.tdYear = Int
y' } | Int
y' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink Int
year ] [TimeDiff] -> [TimeDiff] -> [TimeDiff]
forall a. [a] -> [a] -> [a]
++
[ TimeDiff
td { tdMonth :: Int
OldTime.tdMonth = Int
m' } | Int
m' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink Int
month ] [TimeDiff] -> [TimeDiff] -> [TimeDiff]
forall a. [a] -> [a] -> [a]
++
[ TimeDiff
td { tdDay :: Int
OldTime.tdDay = Int
d' } | Int
d' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink Int
day ] [TimeDiff] -> [TimeDiff] -> [TimeDiff]
forall a. [a] -> [a] -> [a]
++
[ TimeDiff
td { tdHour :: Int
OldTime.tdHour = Int
h' } | Int
h' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink Int
hour ] [TimeDiff] -> [TimeDiff] -> [TimeDiff]
forall a. [a] -> [a] -> [a]
++
[ TimeDiff
td { tdMin :: Int
OldTime.tdMin = Int
m' } | Int
m' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink Int
minute ] [TimeDiff] -> [TimeDiff] -> [TimeDiff]
forall a. [a] -> [a] -> [a]
++
[ TimeDiff
td { tdSec :: Int
OldTime.tdSec = Int
s' } | Int
s' <- Int -> [Int]
forall a. Arbitrary a => a -> [a]
shrink Int
sec ] [TimeDiff] -> [TimeDiff] -> [TimeDiff]
forall a. [a] -> [a] -> [a]
++
[ TimeDiff
td { tdPicosec :: Integer
OldTime.tdPicosec = Integer
p' } | Integer
p' <- Integer -> [Integer]
forall a. Arbitrary a => a -> [a]
shrink Integer
picosec ]
instance CoArbitrary OldTime.TimeDiff where
coarbitrary :: TimeDiff -> Gen b -> Gen b
coarbitrary (OldTime.TimeDiff Int
year Int
month Int
day Int
hour Int
minute Int
sec Integer
picosec) =
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
year (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
month (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
day (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
hour (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
minute (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
sec (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Integer -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Integer
picosec
instance Arbitrary OldTime.CalendarTime where
arbitrary :: Gen CalendarTime
arbitrary = ClockTime -> CalendarTime
OldTime.toUTCTime (ClockTime -> CalendarTime) -> Gen ClockTime -> Gen CalendarTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ClockTime
forall a. Arbitrary a => Gen a
arbitrary
instance CoArbitrary OldTime.CalendarTime where
coarbitrary :: CalendarTime -> Gen b -> Gen b
coarbitrary (OldTime.CalendarTime
Int
year Month
month Int
day Int
hour Int
minute Int
sec Integer
picosec
Day
wDay Int
yDay String
tzName Int
tz Bool
isDST) =
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
year (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Month -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Month
month (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
day (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
hour (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
minute (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
sec (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Integer -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Integer
picosec (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Day -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Day
wDay (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
yDay (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
String -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary String
tzName (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
tz (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Bool -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Bool
isDST