{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}

module Test.Cardano.Ledger.Binary.Vintage.RoundTrip (tests) where

import Data.Fixed (E9, Fixed (..))
import Data.Ratio ((%))
import Hedgehog (Property, Range, checkParallel)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import Test.Cardano.Ledger.Binary.Vintage.Helpers.GoldenRoundTrip (
  roundTripsCBORBuildable,
  roundTripsCBORShow,
 )
import Test.Cardano.Prelude (discoverRoundTrip, eachOf)

tests :: IO Bool
tests :: IO Bool
tests = forall (m :: * -> *). MonadIO m => Group -> m Bool
checkParallel $$String
[(PropertyName, Property)]
Property
String -> PropertyName
String -> GroupName
GroupName -> [(PropertyName, Property)] -> Group
roundTripTextBi :: Property
roundTripByteStringBi :: Property
roundTripSetBi :: Property
roundTripMapBi :: Property
roundTripNanoBi :: Property
roundTripRatioBi :: Property
roundTripInt64Bi :: Property
roundTripInt32Bi :: Property
roundTripFloatBi :: Property
roundTripIntBi :: Property
roundTripWord64Bi :: Property
roundTripWord32Bi :: Property
roundTripWord16Bi :: Property
roundTripWord8Bi :: Property
roundTripWordBi :: Property
roundTripIntegerBi :: Property
roundTripBoolBi :: Property
roundTripUnitBi :: Property
discoverRoundTrip

roundTripUnitBi :: Property
roundTripUnitBi :: Property
roundTripUnitBi = forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1 (forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripBoolBi :: Property
roundTripBoolBi :: Property
roundTripBoolBi = forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
10 forall (m :: * -> *). MonadGen m => m Bool
Gen.bool forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

-- | Tests up to 'Integer's with multiple machine words using large upper bound
roundTripIntegerBi :: Property
roundTripIntegerBi :: Property
roundTripIntegerBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
    TestLimit
1000
    (forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral (forall a. Integral a => a -> a -> a -> Range a
Range.linearFrom Integer
0 (-Integer
1e40) Integer
1e40 :: Range Integer))
    forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripWordBi :: Property
roundTripWordBi :: Property
roundTripWordBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Word -> m Word
Gen.word forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripWord8Bi :: Property
roundTripWord8Bi :: Property
roundTripWord8Bi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Word8 -> m Word8
Gen.word8 forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripWord16Bi :: Property
roundTripWord16Bi :: Property
roundTripWord16Bi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Word16 -> m Word16
Gen.word16 forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripWord32Bi :: Property
roundTripWord32Bi :: Property
roundTripWord32Bi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Word32 -> m Word32
Gen.word32 forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripWord64Bi :: Property
roundTripWord64Bi :: Property
roundTripWord64Bi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Word64 -> m Word64
Gen.word64 forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripIntBi :: Property
roundTripIntBi :: Property
roundTripIntBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Int -> m Int
Gen.int forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripFloatBi :: Property
roundTripFloatBi :: Property
roundTripFloatBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Float -> m Float
Gen.float (forall a. a -> a -> Range a
Range.constant (-Float
1e12) Float
1e12)) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripInt32Bi :: Property
roundTripInt32Bi :: Property
roundTripInt32Bi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Int32 -> m Int32
Gen.int32 forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripInt64Bi :: Property
roundTripInt64Bi :: Property
roundTripInt64Bi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
1000 (forall (m :: * -> *). MonadGen m => Range Int64 -> m Int64
Gen.int64 forall a. (Bounded a, Num a) => Range a
Range.constantBounded) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripRatioBi :: Property
roundTripRatioBi :: Property
roundTripRatioBi =
  let r :: Range.Range Integer
      r :: Range Integer
r = forall a. a -> a -> Range a
Range.constant (-Integer
1_000_000_000_000_0000_000) Integer
1_000_000_000_000_0000_000
   in forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
        TestLimit
1000
        (forall a. Integral a => a -> a -> Ratio a
(%) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral Range Integer
r forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral Range Integer
r)
        forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable

roundTripNanoBi :: Property
roundTripNanoBi :: Property
roundTripNanoBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
    TestLimit
1000
    ((forall k (a :: k). Integer -> Fixed a
MkFixed :: Integer -> Fixed E9) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
Gen.integral (forall a. a -> a -> a -> Range a
Range.constantFrom Integer
0 (-Integer
1e12) Integer
1e12))
    forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Show a, HasCallStack) =>
a -> m ()
roundTripsCBORShow

roundTripMapBi :: Property
roundTripMapBi :: Property
roundTripMapBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
    TestLimit
100
    ( forall (m :: * -> *) k v.
(MonadGen m, Ord k) =>
Range Int -> m (k, v) -> m (Map k v)
Gen.map
        (forall a. a -> a -> Range a
Range.constant Int
0 Int
50)
        ((,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). MonadGen m => Range Int -> m Int
Gen.int forall a. (Bounded a, Num a) => Range a
Range.constantBounded forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall (m :: * -> *). MonadGen m => Range Int -> m Int
Gen.int forall a. (Bounded a, Num a) => Range a
Range.constantBounded)
    )
    forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Show a, HasCallStack) =>
a -> m ()
roundTripsCBORShow

roundTripSetBi :: Property
roundTripSetBi :: Property
roundTripSetBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
    TestLimit
100
    (forall (m :: * -> *) a.
(MonadGen m, Ord a) =>
Range Int -> m a -> m (Set a)
Gen.set (forall a. a -> a -> Range a
Range.constant Int
0 Int
50) (forall (m :: * -> *). MonadGen m => Range Int -> m Int
Gen.int forall a. (Bounded a, Num a) => Range a
Range.constantBounded))
    forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Show a, HasCallStack) =>
a -> m ()
roundTripsCBORShow

roundTripByteStringBi :: Property
roundTripByteStringBi :: Property
roundTripByteStringBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf TestLimit
100 (forall (m :: * -> *). MonadGen m => Range Int -> m ByteString
Gen.bytes forall a b. (a -> b) -> a -> b
$ forall a. a -> a -> Range a
Range.constant Int
0 Int
100) forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Show a, HasCallStack) =>
a -> m ()
roundTripsCBORShow

roundTripTextBi :: Property
roundTripTextBi :: Property
roundTripTextBi =
  forall a.
(Show a, HasCallStack) =>
TestLimit -> Gen a -> (a -> PropertyT IO ()) -> Property
eachOf
    TestLimit
100
    (forall (m :: * -> *). MonadGen m => Range Int -> m Char -> m Text
Gen.text (forall a. a -> a -> Range a
Range.constant Int
0 Int
100) forall (m :: * -> *). MonadGen m => m Char
Gen.unicode)
    forall a (m :: * -> *).
(DecCBOR a, EncCBOR a, Eq a, MonadTest m, Buildable a,
 HasCallStack) =>
a -> m ()
roundTripsCBORBuildable