    -- |
    -- Module:      Hedgehog.Classes.MVector
    -- Copyright:   (c) 2019-2020 Andrew Lelechenko
    -- Licence:     BSD3
    --

    {-# LANGUAGE CPP #-}
    {-# LANGUAGE ScopedTypeVariables #-}

    #if !HAVE_VECTOR

    module Hedgehog.Classes.MVector () where

    #else

    module Hedgehog.Classes.MVector
      ( muvectorLaws
      ) where

    import Control.Monad (when)
    import Control.Monad.ST
    import qualified Data.Vector.Generic.Mutable as MU (basicInitialize)
    import qualified Data.Vector.Unboxed.Mutable as MU

    import Hedgehog
    import Hedgehog.Classes.Common
    import qualified Hedgehog.Gen as Gen
    import qualified Hedgehog.Range as Range

    -- | Test that a 'Vector.Unboxed.MVector' instance obey several laws.
    muvectorLaws :: (Eq a, MU.Unbox a, Show a) => Gen a -> Laws
    muvectorLaws :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Laws
    muvectorLaws Gen a
    gen = String -> [(String, Property)] -> Laws
    Laws String
    "Vector.Unboxed.MVector"
      [ (String
    "New-Length", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    newLength Gen a
    gen)
      , (String
    "Replicate-Length", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    replicateLength Gen a
    gen)
      , (String
    "Slice-Length", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceLength Gen a
    gen)
      , (String
    "Grow-Length", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    growLength Gen a
    gen)

      , (String
    "Write-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeRead Gen a
    gen)
      , (String
    "Set-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    setRead Gen a
    gen)
      , (String
    "Sliced-Set-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedSetRead Gen a
    gen)
      , (String
    "Replicate-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    replicateRead Gen a
    gen)

      , (String
    "Slice-Overlaps", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceOverlaps Gen a
    gen)
      , (String
    "Slice-Copy", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceCopy Gen a
    gen)
      , (String
    "Slice-Move", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceMove Gen a
    gen)

      , (String
    "Write-Copy-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeCopyRead Gen a
    gen)
      , (String
    "Write-Move-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeMoveRead Gen a
    gen)
      , (String
    "Write-Grow-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeGrowRead Gen a
    gen)
      , (String
    "Sliced-Write-Copy-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedWriteCopyRead Gen a
    gen)
      , (String
    "Sliced-Write-Move-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedWriteMoveRead Gen a
    gen)
      , (String
    "Sliced-Write-Grow-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedWriteGrowRead Gen a
    gen)

      , (String
    "Write-InitializeAround-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeInitializeAroundRead Gen a
    gen)
      , (String
    "Write-ClearAround-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeClearAroundRead Gen a
    gen)
      , (String
    "Write-SetAround-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeSetAroundRead Gen a
    gen)
      , (String
    "Write-WriteAround-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeWriteAroundRead Gen a
    gen)
      , (String
    "Write-CopyAround-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeCopyAroundRead Gen a
    gen)
      , (String
    "Write-MoveAround-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeMoveAroundRead Gen a
    gen)

      , (String
    "Write-InitializeBetween-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeInitializeBetweenRead Gen a
    gen)
      , (String
    "Write-ClearBetween-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeClearBetweenRead Gen a
    gen)
      , (String
    "Write-SetBetween-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeSetBetweenRead Gen a
    gen)
      , (String
    "Write-CopyBetween-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeCopyBetweenRead Gen a
    gen)
      , (String
    "Write-MoveBetween-Read", Gen a -> Property
    forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeMoveBetweenRead Gen a
    gen)
      ]

    genNonNegative :: Gen Int
    genNonNegative :: Gen Int
    genNonNegative = Range Int -> Gen Int
    forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
    Gen.integral (Int -> Int -> Range Int
    forall a. Integral a => a -> a -> Range a
    Range.linear Int
    0 Int
    1000)

    genPositive :: Gen Int
    genPositive :: Gen Int
    genPositive = Range Int -> Gen Int
    forall (m :: * -> *) a. (MonadGen m, Integral a) => Range a -> m a
    Gen.integral (Int -> Int -> Range Int
    forall a. Integral a => a -> a -> Range a
    Range.linear Int
    1 Int
    1000)

    -------------------------------------------------------------------------------
    -- Length

    newLength :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    newLength :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    newLength Gen a
    _ = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    len <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      (Int -> Int -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === Int
    len) ((forall s. ST s Int) -> Int
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s Int) -> Int) -> (forall s. ST s Int) -> Int
    forall a b. (a -> b) -> a -> b
    $ MVector s a -> Int
    forall a s. Unbox a => MVector s a -> Int
    MU.length (MVector s a -> Int) -> ST s (MVector s a) -> ST s Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new Int
    len :: ST s (MU.MVector s a)))

    replicateLength :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    replicateLength :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    replicateLength Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a   <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    len <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      (Int -> Int -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === Int
    len) ((forall s. ST s Int) -> Int
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s Int) -> Int) -> (forall s. ST s Int) -> Int
    forall a b. (a -> b) -> a -> b
    $ MVector s a -> Int
    forall a s. Unbox a => MVector s a -> Int
    MU.length (MVector s a -> Int) -> ST s (MVector s a) -> ST s Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Int -> a -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> a -> m (MVector (PrimState m) a)
    MU.replicate Int
    len a
    a)

    sliceLength :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    sliceLength :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceLength Gen a
    _ = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    subLen <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (Int -> Int -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === Int
    subLen) ((forall s. ST s Int) -> Int
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s Int) -> Int) -> (forall s. ST s Int) -> Int
    forall a b. (a -> b) -> a -> b
    $ MVector s a -> Int
    forall a s. Unbox a => MVector s a -> Int
    MU.length (MVector s a -> Int)
    -> (MVector s a -> MVector s a) -> MVector s a -> Int
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    ix Int
    subLen (MVector s a -> Int) -> ST s (MVector s a) -> ST s Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> (Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    subLen Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess) :: ST s (MU.MVector s a)))

    growLength :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    growLength :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    growLength Gen a
    _ = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    len <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    by  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (Int -> Int -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === Int
    len Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    by) (Int -> PropertyT IO ()) -> Int -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s Int) -> Int
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s Int) -> Int) -> (forall s. ST s Int) -> Int
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new Int
    len :: ST s (MU.MVector s a)
        MVector s a -> Int
    forall a s. Unbox a => MVector s a -> Int
    MU.length (MVector s a -> Int) -> ST s (MVector s a) -> ST s Int
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MVector (PrimState (ST s)) a
    -> Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
    MU.grow MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    by

    -------------------------------------------------------------------------------
    -- Read

    writeRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    setRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    setRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    setRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> a -> m ()
    MU.set MVector s a
    MVector (PrimState (ST s)) a
    arr a
    a
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    slicedSetRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    slicedSetRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedSetRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    before <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    after  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> Int -> Int -> ST s (MVector s a)
    forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    before Int
    after (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> a -> m ()
    MU.set MVector s a
    MVector (PrimState (ST s)) a
    arr a
    a
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    replicateRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    replicateRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    replicateRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> a -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> a -> m (MVector (PrimState m) a)
    MU.replicate (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess) a
    a
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    -------------------------------------------------------------------------------
    -- Overlaps

    sliceOverlaps :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    sliceOverlaps :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceOverlaps Gen a
    _ = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      Int
    i  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    ij <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    jk <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    kl <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    lm <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      let j :: Int
    j = Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ij
          k :: Int
    k = Int
    j Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    jk
          l :: Int
    l = Int
    k Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    kl
          m :: Int
    m = Int
    l Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    lm
      (forall s. ST s (PropertyT IO ())) -> PropertyT IO ()
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (PropertyT IO ())) -> PropertyT IO ())
    -> (forall s. ST s (PropertyT IO ())) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    m Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) :: ST s (MU.MVector s a)
        let slice1 :: MVector s a
    slice1 = Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    i (Int
    k Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) MVector s a
    arr
            slice2 :: MVector s a
    slice2 = Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    j (Int
    l Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    j Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) MVector s a
    arr
        PropertyT IO () -> ST s (PropertyT IO ())
    forall a. a -> ST s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (PropertyT IO () -> ST s (PropertyT IO ()))
    -> PropertyT IO () -> ST s (PropertyT IO ())
    forall a b. (a -> b) -> a -> b
    $ Bool -> PropertyT IO ()
    forall (m :: * -> *). (MonadTest m, HasCallStack) => Bool -> m ()
    assert (Bool -> PropertyT IO ()) -> Bool -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ MVector s a -> MVector s a -> Bool
    forall a s. Unbox a => MVector s a -> MVector s a -> Bool
    MU.overlaps MVector s a
    slice1 MVector s a
    slice2

    sliceCopy :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    sliceCopy :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceCopy Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    i      <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    ij     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    jk     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      let j :: Int
    j = Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ij
          k :: Int
    k = Int
    j Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    jk
      (forall s. ST s (PropertyT IO ())) -> PropertyT IO ()
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (PropertyT IO ())) -> PropertyT IO ())
    -> (forall s. ST s (PropertyT IO ())) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new Int
    k :: ST s (MU.MVector s a)
        let src :: MVector s a
    src = Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    i (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess) MVector s a
    arr
            dst :: MVector s a
    dst = Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    j (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess) MVector s a
    arr
        if MVector s a -> MVector s a -> Bool
    forall a s. Unbox a => MVector s a -> MVector s a -> Bool
    MU.overlaps MVector s a
    src MVector s a
    dst then PropertyT IO () -> ST s (PropertyT IO ())
    forall a. a -> ST s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure PropertyT IO ()
    forall (m :: * -> *). MonadTest m => m ()
    success else do
          MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
          MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.copy MVector s a
    MVector (PrimState (ST s)) a
    dst MVector s a
    MVector (PrimState (ST s)) a
    src
          a
    valSrc <- MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix
          a
    valDst <- MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix
          PropertyT IO () -> ST s (PropertyT IO ())
    forall a. a -> ST s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (PropertyT IO () -> ST s (PropertyT IO ()))
    -> PropertyT IO () -> ST s (PropertyT IO ())
    forall a b. (a -> b) -> a -> b
    $ (a
    valSrc, a
    valDst) (a, a) -> (a, a) -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === (a
    a, a
    a)

    sliceMove :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    sliceMove :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    sliceMove Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    i      <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    ij     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    jk     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      let j :: Int
    j = Int
    i Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ij
          k :: Int
    k = Int
    j Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    jk
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new Int
    k :: ST s (MU.MVector s a)
        let src :: MVector s a
    src = Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    i (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess) MVector s a
    arr
            dst :: MVector s a
    dst = Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    j (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess) MVector s a
    arr
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.move MVector s a
    MVector (PrimState (ST s)) a
    dst MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    -------------------------------------------------------------------------------
    -- Write + copy/move/grow

    writeCopyRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeCopyRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeCopyRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector s a
    dst <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.copy MVector s a
    MVector (PrimState (ST s)) a
    dst MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    writeMoveRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeMoveRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeMoveRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector s a
    dst <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.move MVector s a
    MVector (PrimState (ST s)) a
    dst MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    writeGrowRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeGrowRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeGrowRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    by     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector s a
    dst <- MVector (PrimState (ST s)) a
    -> Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
    MU.grow MVector s a
    MVector (PrimState (ST s)) a
    src Int
    by
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    slicedWriteCopyRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    slicedWriteCopyRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedWriteCopyRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a         <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix        <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    beforeSrc <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    afterSrc  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    beforeDst <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    afterDst  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> Int -> Int -> ST s (MVector s a)
    forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    beforeSrc Int
    afterSrc (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector s a
    dst <- Int -> Int -> Int -> ST s (MVector s a)
    forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    beforeDst Int
    afterDst (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.copy MVector s a
    MVector (PrimState (ST s)) a
    dst MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    slicedWriteMoveRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    slicedWriteMoveRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedWriteMoveRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a         <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix        <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    beforeSrc <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    afterSrc  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    beforeDst <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    afterDst  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> Int -> Int -> ST s (MVector s a)
    forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    beforeSrc Int
    afterSrc (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector s a
    dst <- Int -> Int -> Int -> ST s (MVector s a)
    forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    beforeDst Int
    afterDst (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.move MVector s a
    MVector (PrimState (ST s)) a
    dst MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    slicedWriteGrowRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    slicedWriteGrowRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    slicedWriteGrowRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a         <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix        <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    by        <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    beforeSrc <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    afterSrc  <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> Int -> Int -> ST s (MVector s a)
    forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    beforeSrc Int
    afterSrc (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    src Int
    ix a
    a
        MVector s a
    dst <- MVector (PrimState (ST s)) a
    -> Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
    MU.grow MVector s a
    MVector (PrimState (ST s)) a
    src Int
    by
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear MVector s a
    MVector (PrimState (ST s)) a
    src
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    -------------------------------------------------------------------------------
    -- Write + overwrite around

    writeInitializeAroundRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeInitializeAroundRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeInitializeAroundRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    ix Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector s a -> ST s ()
    forall s. MVector s a -> ST s ()
    forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
    MU.basicInitialize (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    arr)
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    excess Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector s a -> ST s ()
    forall s. MVector s a -> ST s ()
    forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
    MU.basicInitialize (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    arr)
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    writeClearAroundRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeClearAroundRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeClearAroundRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    ix Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    arr)
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    excess Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    arr)
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    writeSetAroundRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeSetAroundRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeSetAroundRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    ix Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> a -> m ()
    MU.set (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    arr) a
    b
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    excess Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> a -> m ()
    MU.set (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    arr) a
    b
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    writeWriteAroundRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeWriteAroundRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeWriteAroundRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    ix Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) a
    b
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    excess Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) a
    b
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix

    writeCopyAroundRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeCopyAroundRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeCopyAroundRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector s a
    dst <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix a
    a
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    ix Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.copy (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    dst) (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    src)
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    excess Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.copy (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    dst) (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    src)
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    writeMoveAroundRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeMoveAroundRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeMoveAroundRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      (a -> a -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === a
    a) (a -> PropertyT IO ()) -> a -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s a) -> a
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s a) -> a) -> (forall s. ST s a) -> a
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector s a
    dst <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix a
    a
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    ix Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    0) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.move (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    dst) (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    0 Int
    ix MVector s a
    src)
        Bool -> ST s () -> ST s ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    when (Int
    excess Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    1) (ST s () -> ST s ()) -> ST s () -> ST s ()
    forall a b. (a -> b) -> a -> b
    $
          MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.move (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    dst) (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    excess Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    src)
        MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix

    -------------------------------------------------------------------------------
    -- Two writes + overwrite in between

    writeInitializeBetweenRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeInitializeBetweenRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeInitializeBetweenRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    dix    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      ((a, a) -> (a, a) -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === (a
    a, a
    b)) ((a, a) -> PropertyT IO ()) -> (a, a) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s (a, a)) -> (a, a)
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (a, a)) -> (a, a))
    -> (forall s. ST s (a, a)) -> (a, a)
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix) a
    b
        MVector s a -> ST s ()
    forall s. MVector s a -> ST s ()
    forall (v :: * -> * -> *) a s. MVector v a => v s a -> ST s ()
    MU.basicInitialize (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    arr)
        (,) (a -> a -> (a, a)) -> ST s a -> ST s (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix ST s (a -> (a, a)) -> ST s a -> ST s (a, a)
    forall a b. ST s (a -> b) -> ST s a -> ST s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix)

    writeClearBetweenRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeClearBetweenRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeClearBetweenRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    dix    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      ((a, a) -> (a, a) -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === (a
    a, a
    b)) ((a, a) -> PropertyT IO ()) -> (a, a) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s (a, a)) -> (a, a)
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (a, a)) -> (a, a))
    -> (forall s. ST s (a, a)) -> (a, a)
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix) a
    b
        MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> m ()
    MU.clear (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    arr)
        (,) (a -> a -> (a, a)) -> ST s a -> ST s (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix ST s (a -> (a, a)) -> ST s a -> ST s (a, a)
    forall a b. ST s (a -> b) -> ST s a -> ST s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix)

    writeSetBetweenRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeSetBetweenRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeSetBetweenRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    c      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    dix    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      ((a, a) -> (a, a) -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === (a
    a, a
    b)) ((a, a) -> PropertyT IO ()) -> (a, a) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s (a, a)) -> (a, a)
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (a, a)) -> (a, a))
    -> (forall s. ST s (a, a)) -> (a, a)
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix a
    a
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix) a
    b
        MVector (PrimState (ST s)) a -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> a -> m ()
    MU.set (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    arr) a
    c
        (,) (a -> a -> (a, a)) -> ST s a -> ST s (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr Int
    ix ST s (a -> (a, a)) -> ST s a -> ST s (a, a)
    forall a b. ST s (a -> b) -> ST s a -> ST s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    arr (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix)

    writeCopyBetweenRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeCopyBetweenRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeCopyBetweenRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    dix    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      ((a, a) -> (a, a) -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === (a
    a, a
    b)) ((a, a) -> PropertyT IO ()) -> (a, a) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s (a, a)) -> (a, a)
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (a, a)) -> (a, a))
    -> (forall s. ST s (a, a)) -> (a, a)
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector s a
    dst <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix a
    a
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    dst (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix) a
    b
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.copy (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    dst) (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    src)
        (,) (a -> a -> (a, a)) -> ST s a -> ST s (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix ST s (a -> (a, a)) -> ST s a -> ST s (a, a)
    forall a b. ST s (a -> b) -> ST s a -> ST s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix)

    writeMoveBetweenRead :: forall a. (Eq a, MU.Unbox a, Show a) => Gen a -> Property
    writeMoveBetweenRead :: forall a. (Eq a, Unbox a, Show a) => Gen a -> Property
    writeMoveBetweenRead Gen a
    gen = HasCallStack => PropertyT IO () -> Property
    PropertyT IO () -> Property
    property (PropertyT IO () -> Property) -> PropertyT IO () -> Property
    forall a b. (a -> b) -> a -> b
    $ do
      a
    a      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      a
    b      <- Gen a -> PropertyT IO a
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen a
    gen
      Int
    ix     <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genNonNegative
      Int
    dix    <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      Int
    excess <- Gen Int -> PropertyT IO Int
    forall (m :: * -> *) a.
    (Monad m, Show a, HasCallStack) =>
    Gen a -> PropertyT m a
    forAll Gen Int
    genPositive
      ((a, a) -> (a, a) -> PropertyT IO ()
    forall (m :: * -> *) a.
    (MonadTest m, Eq a, Show a, HasCallStack) =>
    a -> a -> m ()
    === (a
    a, a
    b)) ((a, a) -> PropertyT IO ()) -> (a, a) -> PropertyT IO ()
    forall a b. (a -> b) -> a -> b
    $ (forall s. ST s (a, a)) -> (a, a)
    forall a. (forall s. ST s a) -> a
    runST ((forall s. ST s (a, a)) -> (a, a))
    -> (forall s. ST s (a, a)) -> (a, a)
    forall a b. (a -> b) -> a -> b
    $ do
        MVector s a
    src <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector s a
    dst <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    excess)
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix a
    a
        MVector (PrimState (ST s)) a -> Int -> a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> a -> m ()
    MU.write MVector s a
    MVector (PrimState (ST s)) a
    dst (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix) a
    b
        MVector (PrimState (ST s)) a
    -> MVector (PrimState (ST s)) a -> ST s ()
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> MVector (PrimState m) a -> m ()
    MU.move (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    dst) (Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    1) (Int
    dix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    1) MVector s a
    src)
        (,) (a -> a -> (a, a)) -> ST s a -> ST s (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst Int
    ix ST s (a -> (a, a)) -> ST s a -> ST s (a, a)
    forall a b. ST s (a -> b) -> ST s a -> ST s b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> MVector (PrimState (ST s)) a -> Int -> ST s a
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    MVector (PrimState m) a -> Int -> m a
    MU.read MVector s a
    MVector (PrimState (ST s)) a
    dst (Int
    ix Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    dix)

    -------------------------------------------------------------------------------
    -- Utils

    newSlice :: MU.Unbox a => Int -> Int -> Int -> ST s (MU.MVector s a)
    newSlice :: forall a s. Unbox a => Int -> Int -> Int -> ST s (MVector s a)
    newSlice Int
    before Int
    after Int
    len = do
      MVector s a
    arr <- Int -> ST s (MVector (PrimState (ST s)) a)
    forall (m :: * -> *) a.
    (PrimMonad m, Unbox a) =>
    Int -> m (MVector (PrimState m) a)
    MU.new (Int
    before Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    len Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    after)
      MVector s a -> ST s (MVector s a)
    forall a. a -> ST s a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (MVector s a -> ST s (MVector s a))
    -> MVector s a -> ST s (MVector s a)
    forall a b. (a -> b) -> a -> b
    $ Int -> Int -> MVector s a -> MVector s a
    forall a s. Unbox a => Int -> Int -> MVector s a -> MVector s a
    MU.slice Int
    before Int
    len MVector s a
    arr

    #endif