{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Test.Massiv.Core.Index
  ( DimIx(..)
  , SzNE(..)
  , SzIx(..)
  , SzTiny(..)
  , ixToList
  , arbitraryIx1
  , toIx
  -- * Specs
  -- ** Index
  , specIx1
  , ixSpec
  , ix2UpSpec
  , ixNumSpec
  -- ** Size
  , szNumSpec
  , szSpec
  -- * Re-exports
  , module Data.Massiv.Core.Index
  ) where

import Control.DeepSeq
import Control.Exception (throw)
import Control.Monad
import Data.Foldable as F
import Data.Functor.Identity
import Data.IORef
import Data.Massiv.Array.Unsafe (Sz(SafeSz))
import Data.Massiv.Core.Index
import Data.Proxy
import Data.Typeable
import GHC.Exception (ErrorCall(ErrorCallWithLocation))
import Test.Massiv.Utils


-- | Dimension that is always within bounds of an index
newtype DimIx ix = DimIx Dim deriving Int -> DimIx ix -> ShowS
[DimIx ix] -> ShowS
DimIx ix -> String
(Int -> DimIx ix -> ShowS)
-> (DimIx ix -> String) -> ([DimIx ix] -> ShowS) -> Show (DimIx ix)
forall ix. Int -> DimIx ix -> ShowS
forall ix. [DimIx ix] -> ShowS
forall ix. DimIx ix -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DimIx ix] -> ShowS
$cshowList :: forall ix. [DimIx ix] -> ShowS
show :: DimIx ix -> String
$cshow :: forall ix. DimIx ix -> String
showsPrec :: Int -> DimIx ix -> ShowS
$cshowsPrec :: forall ix. Int -> DimIx ix -> ShowS
Show

deriving instance Arbitrary Dim

-- | Size that will result in a non-empty array.
--
-- prop > \ (neSz :: Sz1) -> totalElem (unSzNE neSz) > 0
-- prop > \ (neSz :: Sz2) -> totalElem (unSzNE neSz) > 0
-- prop > \ (neSz :: Sz3) -> totalElem (unSzNE neSz) > 0
-- prop > \ (neSz :: Sz4) -> totalElem (unSzNE neSz) > 0
-- prop > \ (neSz :: Sz5) -> totalElem (unSzNE neSz) > 0
newtype SzNE ix = SzNE
  { SzNE ix -> Sz ix
unSzNE :: Sz ix
  } deriving (Int -> SzNE ix -> ShowS
[SzNE ix] -> ShowS
SzNE ix -> String
(Int -> SzNE ix -> ShowS)
-> (SzNE ix -> String) -> ([SzNE ix] -> ShowS) -> Show (SzNE ix)
forall ix. Index ix => Int -> SzNE ix -> ShowS
forall ix. Index ix => [SzNE ix] -> ShowS
forall ix. Index ix => SzNE ix -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SzNE ix] -> ShowS
$cshowList :: forall ix. Index ix => [SzNE ix] -> ShowS
show :: SzNE ix -> String
$cshow :: forall ix. Index ix => SzNE ix -> String
showsPrec :: Int -> SzNE ix -> ShowS
$cshowsPrec :: forall ix. Index ix => Int -> SzNE ix -> ShowS
Show)


-- | Non-empty size together with an index that is within bounds of that index.
data SzIx ix = SzIx (Sz ix) ix deriving Int -> SzIx ix -> ShowS
[SzIx ix] -> ShowS
SzIx ix -> String
(Int -> SzIx ix -> ShowS)
-> (SzIx ix -> String) -> ([SzIx ix] -> ShowS) -> Show (SzIx ix)
forall ix. Index ix => Int -> SzIx ix -> ShowS
forall ix. Index ix => [SzIx ix] -> ShowS
forall ix. Index ix => SzIx ix -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SzIx ix] -> ShowS
$cshowList :: forall ix. Index ix => [SzIx ix] -> ShowS
show :: SzIx ix -> String
$cshow :: forall ix. Index ix => SzIx ix -> String
showsPrec :: Int -> SzIx ix -> ShowS
$cshowsPrec :: forall ix. Index ix => Int -> SzIx ix -> ShowS
Show

instance (Index ix, Arbitrary ix) => Arbitrary (Sz ix) where
  arbitrary :: Gen (Sz ix)
arbitrary = do
    Sz ix
sz <- ix -> Sz ix
forall ix. Index ix => ix -> Sz ix
Sz (ix -> Sz ix) -> (ix -> ix) -> ix -> Sz ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex Int -> Int
forall a. Num a => a -> a
abs (ix -> Sz ix) -> Gen ix -> Gen (Sz ix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ix
forall a. Arbitrary a => Gen a
arbitrary
    if Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
50000
      then Gen (Sz ix)
forall a. Arbitrary a => Gen a
arbitrary
      else Sz ix -> Gen (Sz ix)
forall (m :: * -> *) a. Monad m => a -> m a
return Sz ix
sz

instance (Index ix, Arbitrary ix) => Arbitrary (SzNE ix) where
  arbitrary :: Gen (SzNE ix)
arbitrary = Sz ix -> SzNE ix
forall ix. Sz ix -> SzNE ix
SzNE (Sz ix -> SzNE ix) -> (Sz ix -> Sz ix) -> Sz ix -> SzNE ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ix -> Sz ix
forall ix. Index ix => ix -> Sz ix
Sz (ix -> Sz ix) -> (Sz ix -> ix) -> Sz ix -> Sz ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (ix -> ix) -> (Sz ix -> ix) -> Sz ix -> ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sz ix -> ix
forall ix. Sz ix -> ix
unSz (Sz ix -> SzNE ix) -> Gen (Sz ix) -> Gen (SzNE ix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Sz ix)
forall a. Arbitrary a => Gen a
arbitrary

instance (Index ix, Arbitrary ix) => Arbitrary (Stride ix) where
  arbitrary :: Gen (Stride ix)
arbitrary = do
    Positive (Small Int
x) <- Gen (Positive (Small Int))
forall a. Arbitrary a => Gen a
arbitrary
    ix -> Stride ix
forall ix. Index ix => ix -> Stride ix
Stride (ix -> Stride ix) -> (ix -> ix) -> ix -> Stride ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex ((Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1) (Int -> Int) -> (Int -> Int) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
6 Int
x)) (ix -> Stride ix) -> Gen ix -> Gen (Stride ix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ix
forall a. Arbitrary a => Gen a
arbitrary

instance (Index ix, Arbitrary ix) => Arbitrary (SzIx ix) where
  arbitrary :: Gen (SzIx ix)
arbitrary = do
    SzNE Sz ix
sz <- Gen (SzNE ix)
forall a. Arbitrary a => Gen a
arbitrary
    -- Make sure index is within bounds:
    Sz ix -> ix -> SzIx ix
forall ix. Sz ix -> ix -> SzIx ix
SzIx Sz ix
sz (ix -> SzIx ix) -> (ix -> ix) -> ix -> SzIx ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ix -> ix -> ix) -> ix -> ix -> ix
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Int -> Int -> Int) -> ix -> ix -> ix
forall ix. Index ix => (Int -> Int -> Int) -> ix -> ix -> ix
liftIndex2 Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod) (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz) (ix -> SzIx ix) -> Gen ix -> Gen (SzIx ix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen ix
forall a. Arbitrary a => Gen a
arbitrary




newtype SzTiny ix = SzTiny { SzTiny ix -> Sz ix
unSzTiny :: Sz ix }
  deriving (Int -> SzTiny ix -> ShowS
[SzTiny ix] -> ShowS
SzTiny ix -> String
(Int -> SzTiny ix -> ShowS)
-> (SzTiny ix -> String)
-> ([SzTiny ix] -> ShowS)
-> Show (SzTiny ix)
forall ix. Index ix => Int -> SzTiny ix -> ShowS
forall ix. Index ix => [SzTiny ix] -> ShowS
forall ix. Index ix => SzTiny ix -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SzTiny ix] -> ShowS
$cshowList :: forall ix. Index ix => [SzTiny ix] -> ShowS
show :: SzTiny ix -> String
$cshow :: forall ix. Index ix => SzTiny ix -> String
showsPrec :: Int -> SzTiny ix -> ShowS
$cshowsPrec :: forall ix. Index ix => Int -> SzTiny ix -> ShowS
Show, SzTiny ix -> SzTiny ix -> Bool
(SzTiny ix -> SzTiny ix -> Bool)
-> (SzTiny ix -> SzTiny ix -> Bool) -> Eq (SzTiny ix)
forall ix. Eq ix => SzTiny ix -> SzTiny ix -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SzTiny ix -> SzTiny ix -> Bool
$c/= :: forall ix. Eq ix => SzTiny ix -> SzTiny ix -> Bool
== :: SzTiny ix -> SzTiny ix -> Bool
$c== :: forall ix. Eq ix => SzTiny ix -> SzTiny ix -> Bool
Eq)

instance (Arbitrary ix, Index ix) => Arbitrary (SzTiny ix) where
  arbitrary :: Gen (SzTiny ix)
arbitrary = Sz ix -> SzTiny ix
forall ix. Sz ix -> SzTiny ix
SzTiny (Sz ix -> SzTiny ix) -> (Sz ix -> Sz ix) -> Sz ix -> SzTiny ix
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Int) -> Sz ix -> Sz ix
forall ix. Index ix => (Int -> Int) -> Sz ix -> Sz ix
liftSz (Int -> Int -> Int
forall a. Integral a => a -> a -> a
`mod` Int
10) (Sz ix -> SzTiny ix) -> Gen (Sz ix) -> Gen (SzTiny ix)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Sz ix)
forall a. Arbitrary a => Gen a
arbitrary


instance Arbitrary e => Arbitrary (Border e) where
  arbitrary :: Gen (Border e)
arbitrary =
    [Gen (Border e)] -> Gen (Border e)
forall a. [Gen a] -> Gen a
oneof
      [ e -> Border e
forall e. e -> Border e
Fill (e -> Border e) -> Gen e -> Gen (Border e)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen e
forall a. Arbitrary a => Gen a
arbitrary
      , Border e -> Gen (Border e)
forall (m :: * -> *) a. Monad m => a -> m a
return Border e
forall e. Border e
Wrap
      , Border e -> Gen (Border e)
forall (m :: * -> *) a. Monad m => a -> m a
return Border e
forall e. Border e
Edge
      , Border e -> Gen (Border e)
forall (m :: * -> *) a. Monad m => a -> m a
return Border e
forall e. Border e
Reflect
      , Border e -> Gen (Border e)
forall (m :: * -> *) a. Monad m => a -> m a
return Border e
forall e. Border e
Continue
      ]


instance Index ix => Arbitrary (DimIx ix) where
  arbitrary :: Gen (DimIx ix)
arbitrary = do
    Int
n <- Gen Int
forall a. Arbitrary a => Gen a
arbitrary
    DimIx ix -> Gen (DimIx ix)
forall (m :: * -> *) a. Monad m => a -> m a
return (DimIx ix -> Gen (DimIx ix)) -> DimIx ix -> Gen (DimIx ix)
forall a b. (a -> b) -> a -> b
$ Dim -> DimIx ix
forall ix. Dim -> DimIx ix
DimIx (Dim
1 Dim -> Dim -> Dim
forall a. Num a => a -> a -> a
+ (Int -> Dim
Dim Int
n Dim -> Dim -> Dim
forall a. Integral a => a -> a -> a
`mod` Proxy ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (Proxy ix
forall k (t :: k). Proxy t
Proxy :: Proxy ix)))

-- | Generators are quadratic in QuickCheck. Unlike built-in Arbitrary instance for `Int`,
-- this one generates smaller integers
--
-- @since 0.1.0
arbitraryIx1 :: Gen Int
arbitraryIx1 :: Gen Int
arbitraryIx1 = (Int -> Gen Int) -> Gen Int
forall a. (Int -> Gen a) -> Gen a
sized (\Int
s -> Int -> Gen Int -> Gen Int
forall a. Int -> Gen a -> Gen a
resize (Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor (Double -> Int) -> Double -> Int
forall a b. (a -> b) -> a -> b
$ (Double -> Double
forall a. Floating a => a -> a
sqrt :: Double -> Double) (Double -> Double) -> Double -> Double
forall a b. (a -> b) -> a -> b
$ Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
s) Gen Int
forall a. Arbitrary a => Gen a
arbitrary)

-- | Convert an index to a list
--
-- @since 0.1.0
ixToList :: Index ix => ix -> [Int]
ixToList :: ix -> [Int]
ixToList = [Int] -> [Int]
forall a. [a] -> [a]
reverse ([Int] -> [Int]) -> (ix -> [Int]) -> ix -> [Int]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Int] -> Int -> [Int]) -> [Int] -> ix -> [Int]
forall ix a. Index ix => (a -> Int -> a) -> a -> ix -> a
foldlIndex ((Int -> [Int] -> [Int]) -> [Int] -> Int -> [Int]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (:)) []

-- | A fairly slow way to convert from one arbitrary index to another of the same dimension
--
-- @since 0.1.0
toIx ::
     forall ix' ix. (Dimensions ix' ~ Dimensions ix, Index ix', Index ix)
  => ix
  -> ix'
toIx :: ix -> ix'
toIx ix
ix = (ix' -> Dim -> ix') -> ix' -> [Dim] -> ix'
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' ix' -> Dim -> ix'
setEachIndex ix'
forall ix. Index ix => ix
zeroIndex [Dim
1 .. Sz ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Sz ix
forall ix. Index ix => ix -> Sz ix
Sz ix
ix)]
  where
    setEachIndex :: ix' -> Dim -> ix'
setEachIndex ix'
ix' Dim
d = ix' -> Dim -> Int -> ix'
forall ix. (HasCallStack, Index ix) => ix -> Dim -> Int -> ix
setDim' ix'
ix' Dim
d (ix -> Dim -> Int
forall ix. (HasCallStack, Index ix) => ix -> Dim -> Int
getDim' ix
ix Dim
d)

instance Arbitrary Ix0 where
  arbitrary :: Gen Ix0
arbitrary = Ix0 -> Gen Ix0
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ix0
Ix0

instance Arbitrary Ix2 where
  arbitrary :: Gen Ix2
arbitrary = Int -> Int -> Ix2
(:.) (Int -> Int -> Ix2) -> Gen Int -> Gen (Int -> Ix2)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
arbitraryIx1 Gen (Int -> Ix2) -> Gen Int -> Gen Ix2
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Int
arbitraryIx1

instance Arbitrary Ix3 where
  arbitrary :: Gen Ix3
arbitrary = Int -> Ix2 -> Ix3
forall (n :: Nat). Int -> Ix (n - 1) -> IxN n
(:>) (Int -> Ix2 -> Ix3) -> Gen Int -> Gen (Ix2 -> Ix3)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
arbitraryIx1 Gen (Ix2 -> Ix3) -> Gen Ix2 -> Gen Ix3
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Int -> Int -> Ix2
(:.) (Int -> Int -> Ix2) -> Gen Int -> Gen (Int -> Ix2)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
arbitraryIx1 Gen (Int -> Ix2) -> Gen Int -> Gen Ix2
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Int
arbitraryIx1)

instance Arbitrary Ix4 where
  arbitrary :: Gen Ix4
arbitrary = Int -> Ix3 -> Ix4
forall (n :: Nat). Int -> Ix (n - 1) -> IxN n
(:>) (Int -> Ix3 -> Ix4) -> Gen Int -> Gen (Ix3 -> Ix4)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
arbitraryIx1 Gen (Ix3 -> Ix4) -> Gen Ix3 -> Gen Ix4
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Ix3
forall a. Arbitrary a => Gen a
arbitrary

instance Arbitrary Ix5 where
  arbitrary :: Gen Ix5
arbitrary = Int -> Ix4 -> Ix5
forall (n :: Nat). Int -> Ix (n - 1) -> IxN n
(:>) (Int -> Ix4 -> Ix5) -> Gen Int -> Gen (Ix4 -> Ix5)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Int
arbitraryIx1 Gen (Ix4 -> Ix5) -> Gen Ix4 -> Gen Ix5
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Ix4
forall a. Arbitrary a => Gen a
arbitrary

instance CoArbitrary Ix2 where
  coarbitrary :: Ix2 -> Gen b -> Gen b
coarbitrary (Int
i :. Int
j) = Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
i (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
j

instance CoArbitrary Ix3 where
  coarbitrary :: Ix3 -> Gen b -> Gen b
coarbitrary (Int
i :> Ix (3 - 1)
ix) = Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
i (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ix2 -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Ix2
Ix (3 - 1)
ix

instance CoArbitrary Ix4 where
  coarbitrary :: Ix4 -> Gen b -> Gen b
coarbitrary (Int
i :> Ix (4 - 1)
ix) = Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
i (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ix3 -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Ix3
Ix (4 - 1)
ix

instance CoArbitrary Ix5 where
  coarbitrary :: Ix5 -> Gen b -> Gen b
coarbitrary (Int
i :> Ix (5 - 1)
ix) = Int -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Int
i (Gen b -> Gen b) -> (Gen b -> Gen b) -> Gen b -> Gen b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ix4 -> Gen b -> Gen b
forall a b. CoArbitrary a => a -> Gen b -> Gen b
coarbitrary Ix4
Ix (5 - 1)
ix

instance Function Ix2 where
  function :: (Ix2 -> b) -> Ix2 :-> b
function = (Ix2 -> Ix2T) -> (Ix2T -> Ix2) -> (Ix2 -> b) -> Ix2 :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Ix2 -> Ix2T
fromIx2 Ix2T -> Ix2
toIx2

instance Function Ix3 where
  function :: (Ix3 -> b) -> Ix3 :-> b
function = (Ix3 -> Ix3T) -> (Ix3T -> Ix3) -> (Ix3 -> b) -> Ix3 :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Ix3 -> Ix3T
fromIx3 Ix3T -> Ix3
toIx3

instance Function Ix4 where
  function :: (Ix4 -> b) -> Ix4 :-> b
function = (Ix4 -> Ix4T) -> (Ix4T -> Ix4) -> (Ix4 -> b) -> Ix4 :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Ix4 -> Ix4T
fromIx4 Ix4T -> Ix4
toIx4

instance Function Ix5 where
  function :: (Ix5 -> b) -> Ix5 :-> b
function = (Ix5 -> Ix5T) -> (Ix5T -> Ix5) -> (Ix5 -> b) -> Ix5 :-> b
forall b a c.
Function b =>
(a -> b) -> (b -> a) -> (a -> c) -> a :-> c
functionMap Ix5 -> Ix5T
fromIx5 Ix5T -> Ix5
toIx5


prop_IsSafeIndex :: Index ix => SzIx ix -> Bool
prop_IsSafeIndex :: SzIx ix -> Bool
prop_IsSafeIndex (SzIx Sz ix
sz ix
ix) = Sz ix -> ix -> Bool
forall ix. Index ix => Sz ix -> ix -> Bool
isSafeIndex Sz ix
sz ix
ix

prop_RepairSafeIx :: Index ix => SzIx ix -> Property
prop_RepairSafeIx :: SzIx ix -> Property
prop_RepairSafeIx (SzIx Sz ix
sz ix
ix) =
  ix
ix ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Sz ix
-> ix -> (Sz Int -> Int -> Int) -> (Sz Int -> Int -> Int) -> ix
forall ix.
Index ix =>
Sz ix
-> ix -> (Sz Int -> Int -> Int) -> (Sz Int -> Int -> Int) -> ix
repairIndex Sz ix
sz ix
ix (String -> Sz Int -> Int -> Int
forall a a a. (Show a, Show a) => String -> a -> a -> a
errorImpossible String
"below zero") (String -> Sz Int -> Int -> Int
forall a a a. (Show a, Show a) => String -> a -> a -> a
errorImpossible String
"above zero")
  where
    errorImpossible :: String -> a -> a -> a
errorImpossible String
msg a
sz1 a
ix1 =
      String -> a
forall a. HasCallStack => String -> a
error (String -> a) -> String -> a
forall a b. (a -> b) -> a -> b
$ String
"Impossible <" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
msg String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
">: " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
sz1 String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" and " String -> ShowS
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Show a => a -> String
show a
ix1

prop_UnconsCons :: Index ix => ix -> Property
prop_UnconsCons :: ix -> Property
prop_UnconsCons ix
ix = ix
ix ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Int -> Lower ix -> ix) -> (Int, Lower ix) -> ix
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> Lower ix -> ix
forall ix. Index ix => Int -> Lower ix -> ix
consDim (ix -> (Int, Lower ix)
forall ix. Index ix => ix -> (Int, Lower ix)
unconsDim ix
ix)

prop_UnsnocSnoc :: Index ix => ix -> Property
prop_UnsnocSnoc :: ix -> Property
prop_UnsnocSnoc ix
ix = ix
ix ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Lower ix -> Int -> ix) -> (Lower ix, Int) -> ix
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Lower ix -> Int -> ix
forall ix. Index ix => Lower ix -> Int -> ix
snocDim (ix -> (Lower ix, Int)
forall ix. Index ix => ix -> (Lower ix, Int)
unsnocDim ix
ix)

prop_ToFromLinearIndex :: Index ix => SzIx ix -> Property
prop_ToFromLinearIndex :: SzIx ix -> Property
prop_ToFromLinearIndex (SzIx Sz ix
sz ix
ix) =
  Sz ix -> ix -> Bool
forall ix. Index ix => Sz ix -> ix -> Bool
isSafeIndex Sz ix
sz ix
ix Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> ix
ix ix -> ix -> Bool
forall a. Eq a => a -> a -> Bool
== Sz ix -> Int -> ix
forall ix. Index ix => Sz ix -> Int -> ix
fromLinearIndex Sz ix
sz (Sz ix -> ix -> Int
forall ix. Index ix => Sz ix -> ix -> Int
toLinearIndex Sz ix
sz ix
ix)

prop_FromToLinearIndex :: Index ix => SzNE ix -> NonNegative Int -> Property
prop_FromToLinearIndex :: SzNE ix -> NonNegative Int -> Property
prop_FromToLinearIndex (SzNE Sz ix
sz) (NonNegative Int
i) =
  Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
i Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> Int
i Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Sz ix -> ix -> Int
forall ix. Index ix => Sz ix -> ix -> Int
toLinearIndex Sz ix
sz (Sz ix -> Int -> ix
forall ix. Index ix => Sz ix -> Int -> ix
fromLinearIndex Sz ix
sz Int
i)

prop_CountElements :: Index ix => Int -> Sz ix -> Property
prop_CountElements :: Int -> Sz ix -> Property
prop_CountElements Int
thresh Sz ix
sz =
  Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
thresh Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
==
  ix
-> ix
-> ix
-> (Int -> Int -> Bool)
-> Int
-> (ix -> Int -> Int)
-> Int
forall ix a.
Index ix =>
ix -> ix -> ix -> (Int -> Int -> Bool) -> a -> (ix -> a -> a) -> a
iter ix
forall ix. Index ix => ix
zeroIndex (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz) (Int -> ix
forall ix. Index ix => Int -> ix
pureIndex Int
1) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) Int
0 ((Int -> Int) -> ix -> Int -> Int
forall a b. a -> b -> a
const (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1))

prop_IterMonotonic :: Index ix => Int -> Sz ix -> Property
prop_IterMonotonic :: Int -> Sz ix -> Property
prop_IterMonotonic Int
thresh Sz ix
sz =
  Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
thresh Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (Bool, ix) -> Bool
forall a b. (a, b) -> a
fst ((Bool, ix) -> Bool) -> (Bool, ix) -> Bool
forall a b. (a -> b) -> a -> b
$
  ix
-> ix
-> ix
-> (Int -> Int -> Bool)
-> (Bool, ix)
-> (ix -> (Bool, ix) -> (Bool, ix))
-> (Bool, ix)
forall ix a.
Index ix =>
ix -> ix -> ix -> (Int -> Int -> Bool) -> a -> (ix -> a -> a) -> a
iter ((Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex Int -> Int
forall a. Enum a => a -> a
succ ix
forall ix. Index ix => ix
zeroIndex) (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz) (Int -> ix
forall ix. Index ix => Int -> ix
pureIndex Int
1) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) (Bool
True, ix
forall ix. Index ix => ix
zeroIndex) ix -> (Bool, ix) -> (Bool, ix)
forall b. Ord b => b -> (Bool, b) -> (Bool, b)
mono
  where
    mono :: b -> (Bool, b) -> (Bool, b)
mono b
curIx (Bool
prevMono, b
prevIx) =
      let isMono :: Bool
isMono = Bool
prevMono Bool -> Bool -> Bool
&& b
prevIx b -> b -> Bool
forall a. Ord a => a -> a -> Bool
< b
curIx
       in Bool
isMono Bool -> (Bool, b) -> (Bool, b)
`seq` (Bool
isMono, b
curIx)

prop_IterMonotonicM :: Index ix => Int -> Sz ix -> Property
prop_IterMonotonicM :: Int -> Sz ix -> Property
prop_IterMonotonicM Int
thresh Sz ix
sz =
  Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
thresh Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (Bool, ix) -> Bool
forall a b. (a, b) -> a
fst ((Bool, ix) -> Bool) -> (Bool, ix) -> Bool
forall a b. (a -> b) -> a -> b
$
  Identity (Bool, ix) -> (Bool, ix)
forall a. Identity a -> a
runIdentity (Identity (Bool, ix) -> (Bool, ix))
-> Identity (Bool, ix) -> (Bool, ix)
forall a b. (a -> b) -> a -> b
$ ix
-> ix
-> ix
-> (Int -> Int -> Bool)
-> (Bool, ix)
-> (ix -> (Bool, ix) -> Identity (Bool, ix))
-> Identity (Bool, ix)
forall ix (m :: * -> *) a.
(Index ix, Monad m) =>
ix
-> ix -> ix -> (Int -> Int -> Bool) -> a -> (ix -> a -> m a) -> m a
iterM ((Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex Int -> Int
forall a. Enum a => a -> a
succ ix
forall ix. Index ix => ix
zeroIndex) (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz) (Int -> ix
forall ix. Index ix => Int -> ix
pureIndex Int
1) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) (Bool
True, ix
forall ix. Index ix => ix
zeroIndex) ix -> (Bool, ix) -> Identity (Bool, ix)
forall b (m :: * -> *).
(Ord b, Monad m) =>
b -> (Bool, b) -> m (Bool, b)
mono
  where
    mono :: b -> (Bool, b) -> m (Bool, b)
mono b
curIx (Bool
prevMono, b
prevIx) =
      let isMono :: Bool
isMono = Bool
prevMono Bool -> Bool -> Bool
&& b
prevIx b -> b -> Bool
forall a. Ord a => a -> a -> Bool
< b
curIx
       in (Bool, b) -> m (Bool, b)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Bool, b) -> m (Bool, b)) -> (Bool, b) -> m (Bool, b)
forall a b. (a -> b) -> a -> b
$ Bool
isMono Bool -> (Bool, b) -> (Bool, b)
`seq` (Bool
isMono, b
curIx)


prop_IterMonotonicBackwards :: Index ix => Int -> Sz ix -> Property
prop_IterMonotonicBackwards :: Int -> Sz ix -> Property
prop_IterMonotonicBackwards Int
thresh sz :: Sz ix
sz@(Sz ix
szix) =
  Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
thresh Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (Bool, ix) -> Bool
forall a b. (a, b) -> a
fst ((Bool, ix) -> Bool) -> (Bool, ix) -> Bool
forall a b. (a -> b) -> a -> b
$
  ix
-> ix
-> ix
-> (Int -> Int -> Bool)
-> (Bool, ix)
-> (ix -> (Bool, ix) -> (Bool, ix))
-> (Bool, ix)
forall ix a.
Index ix =>
ix -> ix -> ix -> (Int -> Int -> Bool) -> a -> (ix -> a -> a) -> a
iter ((Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex Int -> Int
forall a. Enum a => a -> a
pred ix
szix) ix
forall ix. Index ix => ix
zeroIndex (Int -> ix
forall ix. Index ix => Int -> ix
pureIndex (-Int
1)) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (Bool
True, ix
szix) ix -> (Bool, ix) -> (Bool, ix)
forall b. Ord b => b -> (Bool, b) -> (Bool, b)
mono
  where
    mono :: b -> (Bool, b) -> (Bool, b)
mono b
curIx (Bool
prevMono, b
prevIx) =
      let isMono :: Bool
isMono = Bool
prevMono Bool -> Bool -> Bool
&& b
prevIx b -> b -> Bool
forall a. Ord a => a -> a -> Bool
> b
curIx
       in Bool
isMono Bool -> (Bool, b) -> (Bool, b)
`seq` (Bool
isMono, b
curIx)

prop_IterMonotonicBackwardsM :: Index ix => Int -> Sz ix -> Property
prop_IterMonotonicBackwardsM :: Int -> Sz ix -> Property
prop_IterMonotonicBackwardsM Int
thresh sz :: Sz ix
sz@(Sz ix
szix) =
  Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
thresh Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (Bool, ix) -> Bool
forall a b. (a, b) -> a
fst ((Bool, ix) -> Bool) -> (Bool, ix) -> Bool
forall a b. (a -> b) -> a -> b
$
  Identity (Bool, ix) -> (Bool, ix)
forall a. Identity a -> a
runIdentity (Identity (Bool, ix) -> (Bool, ix))
-> Identity (Bool, ix) -> (Bool, ix)
forall a b. (a -> b) -> a -> b
$ ix
-> ix
-> ix
-> (Int -> Int -> Bool)
-> (Bool, ix)
-> (ix -> (Bool, ix) -> Identity (Bool, ix))
-> Identity (Bool, ix)
forall ix (m :: * -> *) a.
(Index ix, Monad m) =>
ix
-> ix -> ix -> (Int -> Int -> Bool) -> a -> (ix -> a -> m a) -> m a
iterM ((Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex Int -> Int
forall a. Enum a => a -> a
pred ix
szix) ix
forall ix. Index ix => ix
zeroIndex (Int -> ix
forall ix. Index ix => Int -> ix
pureIndex (-Int
1)) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(>=) (Bool
True, ix
szix) ix -> (Bool, ix) -> Identity (Bool, ix)
forall b (m :: * -> *).
(Ord b, Monad m) =>
b -> (Bool, b) -> m (Bool, b)
mono
  where
    mono :: b -> (Bool, b) -> m (Bool, b)
mono b
curIx (Bool
prevMono, b
prevIx) =
      let isMono :: Bool
isMono = Bool
prevMono Bool -> Bool -> Bool
&& b
prevIx b -> b -> Bool
forall a. Ord a => a -> a -> Bool
> b
curIx
       in (Bool, b) -> m (Bool, b)
forall (m :: * -> *) a. Monad m => a -> m a
return ((Bool, b) -> m (Bool, b)) -> (Bool, b) -> m (Bool, b)
forall a b. (a -> b) -> a -> b
$ Bool
isMono Bool -> (Bool, b) -> (Bool, b)
`seq` (Bool
isMono, b
curIx)

prop_LiftLift2 :: Index ix => ix -> Int -> Bool
prop_LiftLift2 :: ix -> Int -> Bool
prop_LiftLift2 ix
ix Int
delta = (Int -> Int -> Int) -> ix -> ix -> ix
forall ix. Index ix => (Int -> Int -> Int) -> ix -> ix -> ix
liftIndex2 Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) ix
ix ((Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
delta) ix
forall ix. Index ix => ix
zeroIndex) ix -> ix -> Bool
forall a. Eq a => a -> a -> Bool
==
                            (Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
delta) ix
ix


prop_BorderRepairSafe :: Index ix => Border ix -> SzNE ix -> ix -> Property
prop_BorderRepairSafe :: Border ix -> SzNE ix -> ix -> Property
prop_BorderRepairSafe border :: Border ix
border@(Fill ix
defIx) (SzNE Sz ix
sz) ix
ix =
  Bool -> Bool
not (Sz ix -> ix -> Bool
forall ix. Index ix => Sz ix -> ix -> Bool
isSafeIndex Sz ix
sz ix
ix) Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> Border ix -> Sz ix -> (ix -> ix) -> ix -> ix
forall ix e. Index ix => Border e -> Sz ix -> (ix -> e) -> ix -> e
handleBorderIndex Border ix
border Sz ix
sz ix -> ix
forall a. a -> a
id ix
ix ix -> ix -> Bool
forall a. Eq a => a -> a -> Bool
== ix
defIx
prop_BorderRepairSafe Border ix
border (SzNE Sz ix
sz) ix
ix =
  Bool -> Bool
not (Sz ix -> ix -> Bool
forall ix. Index ix => Sz ix -> ix -> Bool
isSafeIndex Sz ix
sz ix
ix) Bool -> Bool -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> Sz ix -> ix -> Bool
forall ix. Index ix => Sz ix -> ix -> Bool
isSafeIndex Sz ix
sz (Border ix -> Sz ix -> (ix -> ix) -> ix -> ix
forall ix e. Index ix => Border e -> Sz ix -> (ix -> e) -> ix -> e
handleBorderIndex Border ix
border Sz ix
sz ix -> ix
forall a. a -> a
id ix
ix)


prop_GetDropInsert :: Index ix => DimIx ix -> ix -> Property
prop_GetDropInsert :: DimIx ix -> ix -> Property
prop_GetDropInsert (DimIx Dim
dim) ix
ix =
  Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$
  (IO ix -> ix -> Expectation) -> ix -> IO ix -> Expectation
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO ix -> ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
shouldReturn ix
ix (IO ix -> Expectation) -> IO ix -> Expectation
forall a b. (a -> b) -> a -> b
$ do
    Int
i <- ix -> Dim -> IO Int
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m Int
getDimM ix
ix Dim
dim
    Lower ix
ixL <- ix -> Dim -> IO (Lower ix)
forall (m :: * -> *) ix.
(MonadThrow m, Index ix) =>
ix -> Dim -> m (Lower ix)
dropDimM ix
ix Dim
dim
    Lower ix -> Dim -> Int -> IO ix
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
Lower ix -> Dim -> Int -> m ix
insertDimM Lower ix
ixL Dim
dim Int
i

prop_PullOutInsert :: Index ix => DimIx ix -> ix -> Property
prop_PullOutInsert :: DimIx ix -> ix -> Property
prop_PullOutInsert (DimIx Dim
dim) ix
ix =
  Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$
  (IO ix -> ix -> Expectation) -> ix -> IO ix -> Expectation
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO ix -> ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
shouldReturn ix
ix (IO ix -> Expectation) -> IO ix -> Expectation
forall a b. (a -> b) -> a -> b
$ do
    (Int
i, Lower ix
ixL) <- ix -> Dim -> IO (Int, Lower ix)
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m (Int, Lower ix)
pullOutDimM ix
ix Dim
dim
    Lower ix -> Dim -> Int -> IO ix
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
Lower ix -> Dim -> Int -> m ix
insertDimM Lower ix
ixL Dim
dim Int
i

prop_getDimException :: (Typeable ix, Index ix) => Dim -> ix -> Property
prop_getDimException :: Dim -> ix -> Property
prop_getDimException Dim
d ix
ix =
  (Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
<= Dim
0 Bool -> Bool -> Bool
|| Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
> Maybe ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Maybe ix
forall a. a -> Maybe a
Just ix
ix)) Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==>
  (IndexException -> Bool) -> IO Int -> Property
forall b a exc.
(Testable b, NFData a, Exception exc) =>
(exc -> b) -> IO a -> Property
assertExceptionIO (IndexException -> IndexException -> Bool
forall a. Eq a => a -> a -> Bool
== ix -> Dim -> IndexException
forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException ix
ix Dim
d) (ix -> Dim -> IO Int
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m Int
getDimM ix
ix Dim
d)

prop_setDimException :: (Typeable ix, Index ix) => Dim -> ix -> Int -> Property
prop_setDimException :: Dim -> ix -> Int -> Property
prop_setDimException Dim
d ix
ix Int
i =
  (Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
<= Dim
0 Bool -> Bool -> Bool
|| Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
> Maybe ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Maybe ix
forall a. a -> Maybe a
Just ix
ix)) Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==>
  (IndexException -> Bool) -> IO ix -> Property
forall b a exc.
(Testable b, NFData a, Exception exc) =>
(exc -> b) -> IO a -> Property
assertExceptionIO (IndexException -> IndexException -> Bool
forall a. Eq a => a -> a -> Bool
== ix -> Dim -> IndexException
forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException ix
ix Dim
d) (ix -> Dim -> Int -> IO ix
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> Int -> m ix
setDimM ix
ix Dim
d Int
i)

prop_PullOutDimException :: (Typeable ix, Index ix) => Dim -> ix -> Property
prop_PullOutDimException :: Dim -> ix -> Property
prop_PullOutDimException Dim
d ix
ix =
  (Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
<= Dim
0 Bool -> Bool -> Bool
|| Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
> Maybe ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Maybe ix
forall a. a -> Maybe a
Just ix
ix)) Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==>
  (IndexException -> Bool) -> IO (Int, Lower ix) -> Property
forall b a exc.
(Testable b, NFData a, Exception exc) =>
(exc -> b) -> IO a -> Property
assertExceptionIO (IndexException -> IndexException -> Bool
forall a. Eq a => a -> a -> Bool
== ix -> Dim -> IndexException
forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException ix
ix Dim
d) (ix -> Dim -> IO (Int, Lower ix)
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m (Int, Lower ix)
pullOutDimM ix
ix Dim
d)

prop_InsertDimException ::
     forall ix. (Typeable (Lower ix), Index ix)
  => Dim
  -> Lower ix
  -> Int
  -> Property
prop_InsertDimException :: Dim -> Lower ix -> Int -> Property
prop_InsertDimException Dim
d Lower ix
ix Int
i =
  (Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
<= Dim
0 Bool -> Bool -> Bool
|| Dim
d Dim -> Dim -> Bool
forall a. Ord a => a -> a -> Bool
> IO ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions IO ix
resIO) Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (IndexException -> Bool) -> IO ix -> Property
forall b a exc.
(Testable b, NFData a, Exception exc) =>
(exc -> b) -> IO a -> Property
assertExceptionIO (IndexException -> IndexException -> Bool
forall a. Eq a => a -> a -> Bool
== Lower ix -> Dim -> IndexException
forall ix.
(NFData ix, Eq ix, Show ix, Typeable ix) =>
ix -> Dim -> IndexException
IndexDimensionException Lower ix
ix Dim
d) IO ix
resIO
  where
    resIO :: IO ix
resIO = Lower ix -> Dim -> Int -> IO ix
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
Lower ix -> Dim -> Int -> m ix
insertDimM Lower ix
ix Dim
d Int
i :: IO ix


prop_UnconsGetDrop :: (Index (Lower ix), Index ix) => ix -> Property
prop_UnconsGetDrop :: ix -> Property
prop_UnconsGetDrop ix
ix =
  Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$
  (IO (Int, Lower ix) -> (Int, Lower ix) -> Expectation)
-> (Int, Lower ix) -> IO (Int, Lower ix) -> Expectation
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO (Int, Lower ix) -> (Int, Lower ix) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
shouldReturn (ix -> (Int, Lower ix)
forall ix. Index ix => ix -> (Int, Lower ix)
unconsDim ix
ix) (IO (Int, Lower ix) -> Expectation)
-> IO (Int, Lower ix) -> Expectation
forall a b. (a -> b) -> a -> b
$ do
    Int
i <- ix -> Dim -> IO Int
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m Int
getDimM ix
ix (Maybe ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Maybe ix
forall a. a -> Maybe a
Just ix
ix))
    Lower ix
ixL <- ix -> Dim -> IO (Lower ix)
forall (m :: * -> *) ix.
(MonadThrow m, Index ix) =>
ix -> Dim -> m (Lower ix)
dropDimM ix
ix (Maybe ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Maybe ix
forall a. a -> Maybe a
Just ix
ix))
    (Int, Lower ix) -> IO (Int, Lower ix)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
i, Lower ix
ixL)

prop_UnsnocGetDrop :: (Index (Lower ix), Index ix) => ix -> Property
prop_UnsnocGetDrop :: ix -> Property
prop_UnsnocGetDrop ix
ix =
  Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$
  (IO (Lower ix, Int) -> (Lower ix, Int) -> Expectation)
-> (Lower ix, Int) -> IO (Lower ix, Int) -> Expectation
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO (Lower ix, Int) -> (Lower ix, Int) -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
shouldReturn (ix -> (Lower ix, Int)
forall ix. Index ix => ix -> (Lower ix, Int)
unsnocDim ix
ix) (IO (Lower ix, Int) -> Expectation)
-> IO (Lower ix, Int) -> Expectation
forall a b. (a -> b) -> a -> b
$ do
    Int
i <- ix -> Dim -> IO Int
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m Int
getDimM ix
ix Dim
1
    Lower ix
ixL <- ix -> Dim -> IO (Lower ix)
forall (m :: * -> *) ix.
(MonadThrow m, Index ix) =>
ix -> Dim -> m (Lower ix)
dropDimM ix
ix Dim
1
    (Lower ix, Int) -> IO (Lower ix, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Lower ix
ixL, Int
i)

prop_SetAll :: Index ix => ix -> Property
prop_SetAll :: ix -> Property
prop_SetAll ix
ix = Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$ do
  [Dim] -> IO ix
replaceDims [Dim]
dims IO ix -> ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
`shouldReturn` ix
ix
  [Dim] -> IO ix
replaceDims ([Dim] -> [Dim]
forall a. [a] -> [a]
reverse [Dim]
dims) IO ix -> ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
`shouldReturn` ix
ix
  where
    replaceDims :: [Dim] -> IO ix
replaceDims = (ix -> Dim -> IO ix) -> ix -> [Dim] -> IO ix
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM (\ix
cix Dim
d -> ix -> Dim -> IO Int
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> m Int
getDimM ix
ix Dim
d IO Int -> (Int -> IO ix) -> IO ix
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ix -> Dim -> Int -> IO ix
forall ix (m :: * -> *).
(Index ix, MonadThrow m) =>
ix -> Dim -> Int -> m ix
setDimM ix
cix Dim
d) ix
forall ix. Index ix => ix
zeroIndex
    dims :: [Dim]
dims = [Dim
1 .. Maybe ix -> Dim
forall ix (proxy :: * -> *). Index ix => proxy ix -> Dim
dimensions (ix -> Maybe ix
forall a. a -> Maybe a
Just ix
ix)] :: [Dim]


prop_SetGet :: Index ix => ix -> DimIx ix -> Int -> Property
prop_SetGet :: ix -> DimIx ix -> Int -> Property
prop_SetGet ix
ix (DimIx Dim
dim) Int
n = Int
n Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Dim -> Int
forall ix. (HasCallStack, Index ix) => ix -> Dim -> Int
getDim' (ix -> Dim -> Int -> ix
forall ix. (HasCallStack, Index ix) => ix -> Dim -> Int -> ix
setDim' ix
ix Dim
dim Int
n) Dim
dim



prop_BorderIx1 :: Positive Int -> Border Char -> Fun Ix1 Char -> SzNE Ix1 -> Ix1 -> Property
prop_BorderIx1 :: Positive Int
-> Border Char -> Fun Int Char -> SzNE Int -> Int -> Property
prop_BorderIx1 (Positive Int
period) Border Char
border Fun Int Char
getVal (SzNE Sz Int
sz) Int
ix =
  if Sz Int -> Int -> Bool
forall ix. Index ix => Sz ix -> ix -> Bool
isSafeIndex Sz Int
sz Int
ix
    then Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal Int
ix
    else case Border Char
border of
           Fill Char
defVal -> Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Char
defVal
           Border Char
Wrap ->
             Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===
             Border Char -> Sz Int -> (Int -> Char) -> Int -> Char
forall ix e. Index ix => Border e -> Sz ix -> (ix -> e) -> ix -> e
handleBorderIndex
               Border Char
border
               Sz Int
sz
               (Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal)
               ((Int -> Int -> Int) -> Int -> Int -> Int
forall ix. Index ix => (Int -> Int -> Int) -> ix -> ix -> ix
liftIndex2 Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) ((Int -> Int) -> Int -> Int
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
period) (Sz Int -> Int
forall ix. Sz ix -> ix
unSz Sz Int
sz)) Int
ix)
           Border Char
Edge ->
             if Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0
               then Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal ((Int -> Int) -> Int -> Int
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0) Int
ix)
               else Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal ((Int -> Int -> Int) -> Int -> Int -> Int
forall ix. Index ix => (Int -> Int -> Int) -> ix -> ix -> ix
liftIndex2 Int -> Int -> Int
forall a. Ord a => a -> a -> a
min ((Int -> Int) -> Int -> Int
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
subtract Int
1) (Sz Int -> Int
forall ix. Sz ix -> ix
unSz Sz Int
sz)) Int
ix)
           Border Char
Reflect ->
             Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===
             Border Char -> Sz Int -> (Int -> Char) -> Int -> Char
forall ix e. Index ix => Border e -> Sz ix -> (ix -> e) -> ix -> e
handleBorderIndex
               Border Char
border
               Sz Int
sz
               (Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal)
               ((Int -> Int -> Int) -> Int -> Int -> Int
forall ix. Index ix => (Int -> Int -> Int) -> ix -> ix -> ix
liftIndex2 Int -> Int -> Int
forall a. Num a => a -> a -> a
(+) ((Int -> Int) -> Int -> Int
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Num a => a -> a -> a
* (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int -> Int
forall a. Num a => a -> a
signum Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
period)) (Sz Int -> Int
forall ix. Sz ix -> ix
unSz Sz Int
sz)) Int
ix)
           Border Char
Continue ->
             Char
val Char -> Char -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===
             Border Char -> Sz Int -> (Int -> Char) -> Int -> Char
forall ix e. Index ix => Border e -> Sz ix -> (ix -> e) -> ix -> e
handleBorderIndex
               Border Char
forall e. Border e
Reflect
               Sz Int
sz
               (Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal)
               (if Int
ix Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0
                  then Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
                  else Int
ix Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1)
  where
    val :: Char
val = Border Char -> Sz Int -> (Int -> Char) -> Int -> Char
forall ix e. Index ix => Border e -> Sz ix -> (ix -> e) -> ix -> e
handleBorderIndex Border Char
border Sz Int
sz (Fun Int Char -> Int -> Char
forall a b. Fun a b -> a -> b
apply Fun Int Char
getVal) Int
ix


prop_BinaryNumIx ::
  (Num ix, Index ix) => (forall n . Num n => n -> n -> n) -> ix -> ix -> Property
prop_BinaryNumIx :: (forall a. Num a => a -> a -> a) -> ix -> ix -> Property
prop_BinaryNumIx forall a. Num a => a -> a -> a
f ix
ix1 ix
ix2 = (Int -> Int -> Int) -> [Int] -> [Int] -> [Int]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> Int -> Int
forall a. Num a => a -> a -> a
f (ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList ix
ix1) (ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList ix
ix2) [Int] -> [Int] -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (ix -> ix -> ix
forall a. Num a => a -> a -> a
f ix
ix1 ix
ix2)

prop_UnaryNumIx ::
  (Num ix, Index ix) => (forall n . Num n => n -> n) -> ix -> Property
prop_UnaryNumIx :: (forall a. Num a => a -> a) -> ix -> Property
prop_UnaryNumIx forall a. Num a => a -> a
f ix
ix = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Int
forall a. Num a => a -> a
f (ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList ix
ix) [Int] -> [Int] -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (ix -> ix
forall a. Num a => a -> a
f ix
ix)

prop_BinaryNumSz ::
  (Num ix, Index ix) => (forall n . Num n => n -> n -> n) -> Sz ix -> Sz ix -> Property
prop_BinaryNumSz :: (forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
prop_BinaryNumSz forall a. Num a => a -> a -> a
f Sz ix
sz1 Sz ix
sz2 =
  (Int -> Int -> Int) -> [Int] -> [Int] -> [Int]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> Int -> Int
f' (ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz1)) (ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz2)) [Int] -> [Int] -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (Sz ix -> ix
forall ix. Sz ix -> ix
unSz (Sz ix -> Sz ix -> Sz ix
forall a. Num a => a -> a -> a
f Sz ix
sz1 Sz ix
sz2))
  where
    f' :: Int -> Int -> Int
f' Int
x Int
y = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int -> Int
forall a. Num a => a -> a -> a
f Int
x Int
y)

prop_UnaryNumSz ::
  (Num ix, Index ix) => (forall n . Num n => n -> n) -> Sz ix -> Property
prop_UnaryNumSz :: (forall a. Num a => a -> a) -> Sz ix -> Property
prop_UnaryNumSz forall a. Num a => a -> a
f Sz ix
sz = (Int -> Int) -> [Int] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map Int -> Int
f' (ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz)) [Int] -> [Int] -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> [Int]
forall ix. Index ix => ix -> [Int]
ixToList (Sz ix -> ix
forall ix. Sz ix -> ix
unSz (Sz ix -> Sz ix
forall a. Num a => a -> a
f Sz ix
sz))
  where
    f' :: Int -> Int
f' = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> (Int -> Int) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int
forall a. Num a => a -> a
f



prop_IterLinearM :: Index ix => Sz ix -> NonNegative Int -> Positive Int -> Property
prop_IterLinearM :: Sz ix -> NonNegative Int -> Positive Int -> Property
prop_IterLinearM Sz ix
sz (NonNegative Int
start) (Positive Int
increment) = Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$ do
  [Int]
xs <- Sz ix
-> Int
-> Int
-> Int
-> (Int -> Int -> Bool)
-> [Int]
-> (Int -> ix -> [Int] -> IO [Int])
-> IO [Int]
forall ix (m :: * -> *) a.
(Index ix, Monad m) =>
Sz ix
-> Int
-> Int
-> Int
-> (Int -> Int -> Bool)
-> a
-> (Int -> ix -> a -> m a)
-> m a
iterLinearM Sz ix
sz Int
start (Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz) Int
increment Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) [] ((Int -> ix -> [Int] -> IO [Int]) -> IO [Int])
-> (Int -> ix -> [Int] -> IO [Int]) -> IO [Int]
forall a b. (a -> b) -> a -> b
$ \Int
i ix
ix [Int]
acc -> do
    Sz ix -> ix -> Int
forall ix. Index ix => Sz ix -> ix -> Int
toLinearIndex Sz ix
sz ix
ix Int -> Int -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Int
i
    [Int] -> IO [Int]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Int
iInt -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
acc)
  [Int] -> [Int]
forall a. [a] -> [a]
reverse [Int]
xs [Int] -> [Int] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [Int
start, Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
increment .. Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]

prop_IterLinearM_ :: Index ix => Sz ix -> NonNegative Int -> Positive Int -> Property
prop_IterLinearM_ :: Sz ix -> NonNegative Int -> Positive Int -> Property
prop_IterLinearM_ Sz ix
sz (NonNegative Int
start) (Positive Int
increment) = Expectation -> Property
forall prop. Testable prop => prop -> Property
property (Expectation -> Property) -> Expectation -> Property
forall a b. (a -> b) -> a -> b
$ do
  IORef [Int]
ref <- [Int] -> IO (IORef [Int])
forall a. a -> IO (IORef a)
newIORef []
  Sz ix
-> Int
-> Int
-> Int
-> (Int -> Int -> Bool)
-> (Int -> ix -> Expectation)
-> Expectation
forall ix (m :: * -> *).
(Index ix, Monad m) =>
Sz ix
-> Int
-> Int
-> Int
-> (Int -> Int -> Bool)
-> (Int -> ix -> m ())
-> m ()
iterLinearM_ Sz ix
sz Int
start (Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz) Int
increment Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
(<) ((Int -> ix -> Expectation) -> Expectation)
-> (Int -> ix -> Expectation) -> Expectation
forall a b. (a -> b) -> a -> b
$ \Int
i ix
ix -> do
    Sz ix -> ix -> Int
forall ix. Index ix => Sz ix -> ix -> Int
toLinearIndex Sz ix
sz ix
ix Int -> Int -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Int
i
    IORef [Int] -> ([Int] -> [Int]) -> Expectation
forall a. IORef a -> (a -> a) -> Expectation
modifyIORef' IORef [Int]
ref (Int
iInt -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:)
  [Int]
xs <- IORef [Int] -> IO [Int]
forall a. IORef a -> IO a
readIORef IORef [Int]
ref
  [Int] -> [Int]
forall a. [a] -> [a]
reverse [Int]
xs [Int] -> [Int] -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` [Int
start, Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
increment .. Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1]

-----------
-- Specs --
-----------

specIx1 :: Spec
specIx1 :: Spec
specIx1 = String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Ix1" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
  (Typeable (Lower Int), Arbitrary (Lower Int), Typeable Int,
 Index Int, Arbitrary Int, IsIndexDimension Int (Dimensions Int)) =>
Spec
forall ix.
(Typeable (Lower ix), Arbitrary (Lower ix), Typeable ix, Index ix,
 Arbitrary ix, IsIndexDimension ix (Dimensions ix)) =>
Spec
ixSpec @Ix1
  (Typeable Int, Num Int, Index Int, Arbitrary Int) => Spec
forall ix. (Typeable ix, Num ix, Index ix, Arbitrary ix) => Spec
ixNumSpec @Ix1
  String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"Border" (Property -> SpecWith (Arg Property))
-> Property -> SpecWith (Arg Property)
forall a b. (a -> b) -> a -> b
$ (Positive Int
 -> Border Char -> Fun Int Char -> SzNE Int -> Int -> Property)
-> Property
forall prop. Testable prop => prop -> Property
property Positive Int
-> Border Char -> Fun Int Char -> SzNE Int -> Int -> Property
prop_BorderIx1


ixSpec ::
     forall ix. (Typeable (Lower ix), Arbitrary (Lower ix), Typeable ix, Index ix, Arbitrary ix
                , IsIndexDimension ix (Dimensions ix))
  => Spec
ixSpec :: Spec
ixSpec = do
  let threshold :: Int
threshold = Int
50000
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Safety" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (SzIx ix -> Bool) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"IsSafeIndex" ((SzIx ix -> Bool) -> Spec) -> (SzIx ix -> Bool) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => SzIx ix -> Bool
forall ix. Index ix => SzIx ix -> Bool
prop_IsSafeIndex @ix
    String -> (SzIx ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"RepairSafeIx" ((SzIx ix -> Property) -> Spec) -> (SzIx ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => SzIx ix -> Property
forall ix. Index ix => SzIx ix -> Property
prop_RepairSafeIx @ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Lifting" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$
    String -> (ix -> Int -> Bool) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Lift/Lift2" ((ix -> Int -> Bool) -> Spec) -> (ix -> Int -> Bool) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => ix -> Int -> Bool
forall ix. Index ix => ix -> Int -> Bool
prop_LiftLift2 @ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Linear" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (SzIx ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"ToFromLinearIndex" ((SzIx ix -> Property) -> Spec) -> (SzIx ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => SzIx ix -> Property
forall ix. Index ix => SzIx ix -> Property
prop_ToFromLinearIndex @ix
    String -> (SzNE ix -> NonNegative Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"FromToLinearIndex" ((SzNE ix -> NonNegative Int -> Property) -> Spec)
-> (SzNE ix -> NonNegative Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => SzNE ix -> NonNegative Int -> Property
forall ix. Index ix => SzNE ix -> NonNegative Int -> Property
prop_FromToLinearIndex @ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Iterator" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"CountElements" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Int -> Sz ix -> Property
forall ix. Index ix => Int -> Sz ix -> Property
prop_CountElements @ix Int
threshold
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"Monotonic" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Int -> Sz ix -> Property
forall ix. Index ix => Int -> Sz ix -> Property
prop_IterMonotonic @ix Int
threshold
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"MonotonicBackwards" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Int -> Sz ix -> Property
forall ix. Index ix => Int -> Sz ix -> Property
prop_IterMonotonicBackwards @ix Int
threshold
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"MonotonicM" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Int -> Sz ix -> Property
forall ix. Index ix => Int -> Sz ix -> Property
prop_IterMonotonicM @ix Int
threshold
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"MonotonicBackwardsM" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Int -> Sz ix -> Property
forall ix. Index ix => Int -> Sz ix -> Property
prop_IterMonotonicBackwardsM @ix Int
threshold
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Border" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$
    String -> (Border ix -> SzNE ix -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"BorderRepairSafe" ((Border ix -> SzNE ix -> ix -> Property) -> Spec)
-> (Border ix -> SzNE ix -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => Border ix -> SzNE ix -> ix -> Property
forall ix. Index ix => Border ix -> SzNE ix -> ix -> Property
prop_BorderRepairSafe @ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"SetGetDrop" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SetAll" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => ix -> Property
forall ix. Index ix => ix -> Property
prop_SetAll @ix
    String -> (ix -> DimIx ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SetGet" ((ix -> DimIx ix -> Int -> Property) -> Spec)
-> (ix -> DimIx ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => ix -> DimIx ix -> Int -> Property
forall ix. Index ix => ix -> DimIx ix -> Int -> Property
prop_SetGet @ix
    String -> (DimIx ix -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"GetDropInsert" ((DimIx ix -> ix -> Property) -> Spec)
-> (DimIx ix -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => DimIx ix -> ix -> Property
forall ix. Index ix => DimIx ix -> ix -> Property
prop_GetDropInsert @ix
    String -> (DimIx ix -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PullOutInsert" ((DimIx ix -> ix -> Property) -> Spec)
-> (DimIx ix -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => DimIx ix -> ix -> Property
forall ix. Index ix => DimIx ix -> ix -> Property
prop_PullOutInsert @ix
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"UnconsCons" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => ix -> Property
forall ix. Index ix => ix -> Property
prop_UnconsCons @ix
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"UnsnocSnoc" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => ix -> Property
forall ix. Index ix => ix -> Property
prop_UnsnocSnoc @ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"IndexDimensionException" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (Dim -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"getDimException" ((Dim -> ix -> Property) -> Spec)
-> (Dim -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (Typeable ix, Index ix) => Dim -> ix -> Property
forall ix. (Typeable ix, Index ix) => Dim -> ix -> Property
prop_getDimException @ix
    String -> (Dim -> ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"setDimException" ((Dim -> ix -> Int -> Property) -> Spec)
-> (Dim -> ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (Typeable ix, Index ix) => Dim -> ix -> Int -> Property
forall ix. (Typeable ix, Index ix) => Dim -> ix -> Int -> Property
prop_setDimException @ix
    String -> (Dim -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PullOutDimException" ((Dim -> ix -> Property) -> Spec)
-> (Dim -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (Typeable ix, Index ix) => Dim -> ix -> Property
forall ix. (Typeable ix, Index ix) => Dim -> ix -> Property
prop_PullOutDimException @ix
    String -> (Dim -> Lower ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"InsertDimException" ((Dim -> Lower ix -> Int -> Property) -> Spec)
-> (Dim -> Lower ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (Typeable (Lower ix), Index ix) =>
Dim -> Lower ix -> Int -> Property
forall ix.
(Typeable (Lower ix), Index ix) =>
Dim -> Lower ix -> Int -> Property
prop_InsertDimException @ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Dimension" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"GetInnerDimension" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \(ix
ix :: ix) -> ix -> Int
forall ix. Index ix => ix -> Int
lastDim ix
ix Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Dimension 1 -> Int
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> Int
getDimension ix
ix Dimension 1
Dim1
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"GetOuterDimension" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(ix
ix :: ix) -> ix -> Int
forall ix. Index ix => ix -> Int
headDim ix
ix Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Dimension (Dimensions ix) -> Int
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> Int
getDimension ix
ix (Dimension (Dimensions ix)
forall (n :: Nat). (1 <= n, KnownNat n) => Dimension n
DimN :: Dimension (Dimensions ix))
    String -> (ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SetInnerDimension" ((ix -> Int -> Property) -> Spec)
-> (ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(ix
ix :: ix) Int
i -> Lower ix -> Int -> ix
forall ix. Index ix => Lower ix -> Int -> ix
snocDim (ix -> Lower ix
forall ix. Index ix => ix -> Lower ix
initDim ix
ix) Int
i ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Dimension 1 -> Int -> ix
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> Int -> ix
setDimension ix
ix Dimension 1
Dim1 Int
i
    String -> (ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SetOuterDimension" ((ix -> Int -> Property) -> Spec)
-> (ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(ix
ix :: ix) Int
i -> Int -> Lower ix -> ix
forall ix. Index ix => Int -> Lower ix -> ix
consDim Int
i (ix -> Lower ix
forall ix. Index ix => ix -> Lower ix
tailDim ix
ix) ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===
                       ix -> Dimension (Dimensions ix) -> Int -> ix
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> Int -> ix
setDimension ix
ix (Dimension (Dimensions ix)
forall (n :: Nat). (1 <= n, KnownNat n) => Dimension n
DimN :: Dimension (Dimensions ix)) Int
i
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"DropInnerDimension" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \(ix
ix :: ix) -> ix -> Lower ix
forall ix. Index ix => ix -> Lower ix
initDim ix
ix Lower ix -> Lower ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Dimension 1 -> Lower ix
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> Lower ix
dropDimension ix
ix Dimension 1
Dim1
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"DropOuterDimension" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(ix
ix :: ix) -> ix -> Lower ix
forall ix. Index ix => ix -> Lower ix
tailDim ix
ix Lower ix -> Lower ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Dimension (Dimensions ix) -> Lower ix
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> Lower ix
dropDimension ix
ix (Dimension (Dimensions ix)
forall (n :: Nat). (1 <= n, KnownNat n) => Dimension n
DimN :: Dimension (Dimensions ix))
    String -> (Lower ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"InsertInnerDimension" ((Lower ix -> Int -> Property) -> Spec)
-> (Lower ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(Lower ix
ixl :: Lower ix) Int
i -> (Lower ix -> Int -> ix
forall ix. Index ix => Lower ix -> Int -> ix
snocDim Lower ix
ixl Int
i :: ix) ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Lower ix -> Dimension 1 -> Int -> ix
forall ix (n :: Nat).
IsIndexDimension ix n =>
Lower ix -> Dimension n -> Int -> ix
insertDimension Lower ix
ixl Dimension 1
Dim1 Int
i
    String -> (Lower ix -> Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"InsertOuterDimension" ((Lower ix -> Int -> Property) -> Spec)
-> (Lower ix -> Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(Lower ix
ixl :: Lower ix) Int
i -> (Int -> Lower ix -> ix
forall ix. Index ix => Int -> Lower ix -> ix
consDim Int
i Lower ix
ixl :: ix) ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===
                               Lower ix -> Dimension (Dimensions ix) -> Int -> ix
forall ix (n :: Nat).
IsIndexDimension ix n =>
Lower ix -> Dimension n -> Int -> ix
insertDimension Lower ix
ixl (Dimension (Dimensions ix)
forall (n :: Nat). (1 <= n, KnownNat n) => Dimension n
DimN :: Dimension (Dimensions ix)) Int
i
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PullOutInnerDimension" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(ix
ix :: ix) -> ix -> (Lower ix, Int)
forall ix. Index ix => ix -> (Lower ix, Int)
unsnocDim ix
ix (Lower ix, Int) -> (Lower ix, Int) -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Int -> Lower ix -> (Lower ix, Int))
-> (Int, Lower ix) -> (Lower ix, Int)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Lower ix -> Int -> (Lower ix, Int))
-> Int -> Lower ix -> (Lower ix, Int)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,)) (ix -> Dimension 1 -> (Int, Lower ix)
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> (Int, Lower ix)
pullOutDimension ix
ix Dimension 1
Dim1)
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PullInnerOuterDimension" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(ix
ix :: ix) -> ix -> (Int, Lower ix)
forall ix. Index ix => ix -> (Int, Lower ix)
unconsDim ix
ix (Int, Lower ix) -> (Int, Lower ix) -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===
                               ix -> Dimension (Dimensions ix) -> (Int, Lower ix)
forall ix (n :: Nat).
IsIndexDimension ix n =>
ix -> Dimension n -> (Int, Lower ix)
pullOutDimension ix
ix (Dimension (Dimensions ix)
forall (n :: Nat). (1 <= n, KnownNat n) => Dimension n
DimN :: Dimension (Dimensions ix))

  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"NFData" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"rnf" (Property -> SpecWith (Arg Property))
-> Property -> SpecWith (Arg Property)
forall a b. (a -> b) -> a -> b
$ (ix -> Expectation) -> Property
forall prop. Testable prop => prop -> Property
property ((ix -> Expectation) -> Property)
-> (ix -> Expectation) -> Property
forall a b. (a -> b) -> a -> b
$ \ (ix
ix :: ix) -> ix -> ()
forall a. NFData a => a -> ()
rnf ix
ix () -> () -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` ()
    String -> Property -> SpecWith (Arg Property)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"throws exception" (Property -> SpecWith (Arg Property))
-> Property -> SpecWith (Arg Property)
forall a b. (a -> b) -> a -> b
$ (DimIx ix -> ix -> Property) -> Property
forall prop. Testable prop => prop -> Property
property ((DimIx ix -> ix -> Property) -> Property)
-> (DimIx ix -> ix -> Property) -> Property
forall a b. (a -> b) -> a -> b
$ \ (DimIx Dim
d :: DimIx ix) (ix
ix :: ix) ->
      (ExpectedException -> Bool) -> ix -> Property
forall b a exc.
(Testable b, NFData a, Exception exc) =>
(exc -> b) -> a -> Property
assertException (ExpectedException -> ExpectedException -> Bool
forall a. Eq a => a -> a -> Bool
== ExpectedException
ExpectedException) (ix -> Dim -> Int -> ix
forall ix. (HasCallStack, Index ix) => ix -> Dim -> Int -> ix
setDim' ix
ix Dim
d (ExpectedException -> Int
forall a e. Exception e => e -> a
throw ExpectedException
ExpectedException))


ix2UpSpec ::
     forall ix. (Index ix, Index (Lower ix), Arbitrary ix, Arbitrary (Lower ix), Typeable (Lower ix))
  => Spec
ix2UpSpec :: Spec
ix2UpSpec =
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Higher/Lower" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"UnconsGetDrop" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (Index (Lower ix), Index ix) => ix -> Property
forall ix. (Index (Lower ix), Index ix) => ix -> Property
prop_UnconsGetDrop @ix
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"UnsnocGetDrop" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (Index (Lower ix), Index ix) => ix -> Property
forall ix. (Index (Lower ix), Index ix) => ix -> Property
prop_UnsnocGetDrop @ix


-- | Spec that validates the Num instance for any `Index ix => ix`
ixNumSpec :: forall ix . (Typeable ix, Num ix, Index ix, Arbitrary ix) => Spec
ixNumSpec :: Spec
ixNumSpec = do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe (String
"Num (" String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall t. Typeable t => ShowS
showsType @ix String
")") (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (ix -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(+)" ((ix -> ix -> Property) -> Spec) -> (ix -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a -> a) -> ix -> ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a -> a) -> ix -> ix -> Property
prop_BinaryNumIx @ix forall a. Num a => a -> a -> a
(+)
    String -> (ix -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(-)" ((ix -> ix -> Property) -> Spec) -> (ix -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a -> a) -> ix -> ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a -> a) -> ix -> ix -> Property
prop_BinaryNumIx @ix (-)
    String -> (ix -> ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(*)" ((ix -> ix -> Property) -> Spec) -> (ix -> ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a -> a) -> ix -> ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a -> a) -> ix -> ix -> Property
prop_BinaryNumIx @ix forall a. Num a => a -> a -> a
(*)
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"negate" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a) -> ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a) -> ix -> Property
prop_UnaryNumIx @ix forall a. Num a => a -> a
negate
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"abs" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a) -> ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a) -> ix -> Property
prop_UnaryNumIx @ix forall a. Num a => a -> a
abs
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"signum" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a) -> ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a) -> ix -> Property
prop_UnaryNumIx @ix forall a. Num a => a -> a
signum
    String -> (Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"fromInteger" ((Int -> Property) -> Spec) -> (Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \ (Int
i :: Int) ->
      (Int -> ix
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i :: ix) ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a b. a -> b -> a
const Int
i) ix
forall ix. Index ix => ix
zeroIndex
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Constants" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Expectation -> SpecWith (Arg Expectation)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"zeroIndex" (Expectation -> SpecWith (Arg Expectation))
-> Expectation -> SpecWith (Arg Expectation)
forall a b. (a -> b) -> a -> b
$ (ix
forall ix. Index ix => ix
zeroIndex :: ix) ix -> ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` ix
0
    String -> Expectation -> SpecWith (Arg Expectation)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"oneIndex" (Expectation -> SpecWith (Arg Expectation))
-> Expectation -> SpecWith (Arg Expectation)
forall a b. (a -> b) -> a -> b
$ (ix
forall ix. Index ix => ix
oneIndex :: ix) ix -> ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` ix
1

-- | Spec that validates the Num instance for any `Index ix => Sz ix`
szNumSpec :: forall ix . (Typeable ix, Num ix, Index ix, Arbitrary ix) => Spec
szNumSpec :: Spec
szNumSpec = do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe (String
"Num (" String -> ShowS
forall a. [a] -> [a] -> [a]
++ ShowS
forall t. Typeable t => ShowS
showsType @(Sz ix) String
")") (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (Sz ix -> Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(+)" ((Sz ix -> Sz ix -> Property) -> Spec)
-> (Sz ix -> Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
prop_BinaryNumSz @ix forall a. Num a => a -> a -> a
(+)
    String -> (Sz ix -> Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(-)" ((Sz ix -> Sz ix -> Property) -> Spec)
-> (Sz ix -> Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
prop_BinaryNumSz @ix (-)
    String -> (Sz ix -> Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"(*)" ((Sz ix -> Sz ix -> Property) -> Spec)
-> (Sz ix -> Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a -> a) -> Sz ix -> Sz ix -> Property
prop_BinaryNumSz @ix forall a. Num a => a -> a -> a
(*)
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"negate (throws error on non-zero)" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \Sz ix
sz ->
      Sz ix
sz Sz ix -> Sz ix -> Bool
forall a. Eq a => a -> a -> Bool
/= Sz ix
forall ix. Index ix => Sz ix
zeroSz Bool -> Property -> Property
forall prop. Testable prop => Bool -> prop -> Property
==> (ErrorCall -> Bool) -> Sz ix -> Property
forall b a exc.
(Testable b, NFData a, Exception exc) =>
(exc -> b) -> a -> Property
assertException
                       (\(ErrorCallWithLocation String
err String
loc) -> String
err String -> ShowS
forall a b. NFData a => a -> b -> b
`deepseq` String
loc String -> Bool -> Bool
forall a b. NFData a => a -> b -> b
`deepseq` Bool
True)
                       (Sz ix -> Sz ix
forall a. Num a => a -> a
negate Sz ix
sz :: Sz ix)

    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"abs" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a) -> Sz ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a) -> Sz ix -> Property
prop_UnaryNumSz @ix forall a. Num a => a -> a
abs
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"signum" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ (forall a. Num a => a -> a) -> Sz ix -> Property
forall ix.
(Num ix, Index ix) =>
(forall a. Num a => a -> a) -> Sz ix -> Property
prop_UnaryNumSz @ix forall a. Num a => a -> a
signum
    String -> (Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"fromInteger" ((Int -> Property) -> Spec) -> (Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \ (Int
i :: Int) ->
      (Int -> Sz ix
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
i :: Sz ix) Sz ix -> Sz ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== ix -> Sz ix
forall ix. ix -> Sz ix
SafeSz (Int -> ix
forall ix. Index ix => Int -> ix
pureIndex (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 Int
i))
    String -> (ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"fromIx" ((ix -> Property) -> Spec) -> (ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \ (ix
ix :: ix) -> Sz ix -> ix
forall ix. Sz ix -> ix
unSz (ix -> Sz ix
forall ix. Index ix => ix -> Sz ix
Sz ix
ix) ix -> ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Int -> Int) -> ix -> ix
forall ix. Index ix => (Int -> Int) -> ix -> ix
liftIndex (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0) ix
ix
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Constants" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> Expectation -> SpecWith (Arg Expectation)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"zeroSz" (Expectation -> SpecWith (Arg Expectation))
-> Expectation -> SpecWith (Arg Expectation)
forall a b. (a -> b) -> a -> b
$ (Sz ix
forall ix. Index ix => Sz ix
zeroSz :: Sz ix) Sz ix -> Sz ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Sz ix
0
    String -> Expectation -> SpecWith (Arg Expectation)
forall a.
(HasCallStack, Example a) =>
String -> a -> SpecWith (Arg a)
it String
"oneSz" (Expectation -> SpecWith (Arg Expectation))
-> Expectation -> SpecWith (Arg Expectation)
forall a b. (a -> b) -> a -> b
$ (Sz ix
forall ix. Index ix => Sz ix
oneSz :: Sz ix) Sz ix -> Sz ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => a -> a -> Expectation
`shouldBe` Sz ix
1


prop_PullOutInsertSize :: Index ix => DimIx ix -> Sz ix -> Property
prop_PullOutInsertSize :: DimIx ix -> Sz ix -> Property
prop_PullOutInsertSize (DimIx Dim
dim) Sz ix
sz =
  (SomeException -> Property)
-> (Sz ix -> Property) -> Either SomeException (Sz ix) -> Property
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either SomeException -> Property
forall a e. Exception e => e -> a
throw (Sz ix
sz Sz ix -> Sz ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
===) (Either SomeException (Sz ix) -> Property)
-> Either SomeException (Sz ix) -> Property
forall a b. (a -> b) -> a -> b
$ do
    (Sz Int
i, Sz (Lower ix)
szL) <- Sz ix -> Dim -> Either SomeException (Sz Int, Sz (Lower ix))
forall (m :: * -> *) ix.
(MonadThrow m, Index ix) =>
Sz ix -> Dim -> m (Sz Int, Sz (Lower ix))
pullOutSzM Sz ix
sz Dim
dim
    Sz (Lower ix) -> Dim -> Sz Int -> Either SomeException (Sz ix)
forall (m :: * -> *) ix.
(MonadThrow m, Index ix) =>
Sz (Lower ix) -> Dim -> Sz Int -> m (Sz ix)
insertSzM Sz (Lower ix)
szL Dim
dim Sz Int
i


szSpec ::
     forall ix. (Index ix, Arbitrary ix)
  => Spec
szSpec :: Spec
szSpec = do
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Higher/Lower" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"LiftSzNegate" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \ (Sz ix
sz :: Sz ix) -> (Int -> Int) -> Sz ix -> Sz ix
forall ix. Index ix => (Int -> Int) -> Sz ix -> Sz ix
liftSz Int -> Int
forall a. Num a => a -> a
negate Sz ix
sz Sz ix -> Sz ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== Sz ix
forall ix. Index ix => Sz ix
zeroSz
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"UnconsCons" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \ (Sz ix
sz :: Sz ix) -> Sz ix
sz Sz ix -> Sz ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Sz Int -> Sz (Lower ix) -> Sz ix)
-> (Sz Int, Sz (Lower ix)) -> Sz ix
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Sz Int -> Sz (Lower ix) -> Sz ix
forall ix. Index ix => Sz Int -> Sz (Lower ix) -> Sz ix
consSz (Sz ix -> (Sz Int, Sz (Lower ix))
forall ix. Index ix => Sz ix -> (Sz Int, Sz (Lower ix))
unconsSz Sz ix
sz)
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"UnsnocSnoc" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ \ (Sz ix
sz :: Sz ix) -> Sz ix
sz Sz ix -> Sz ix -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Sz (Lower ix) -> Sz Int -> Sz ix)
-> (Sz (Lower ix), Sz Int) -> Sz ix
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Sz (Lower ix) -> Sz Int -> Sz ix
forall ix. Index ix => Sz (Lower ix) -> Sz Int -> Sz ix
snocSz (Sz ix -> (Sz (Lower ix), Sz Int)
forall ix. Index ix => Sz ix -> (Sz (Lower ix), Sz Int)
unsnocSz Sz ix
sz)
    String -> (DimIx ix -> Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"PullOutInsert" ((DimIx ix -> Sz ix -> Property) -> Spec)
-> (DimIx ix -> Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => DimIx ix -> Sz ix -> Property
forall ix. Index ix => DimIx ix -> Sz ix -> Property
prop_PullOutInsertSize @ix
    String -> (Sz ix -> Sz Int -> Expectation) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"SetSzInnerSnoc" ((Sz ix -> Sz Int -> Expectation) -> Spec)
-> (Sz ix -> Sz Int -> Expectation) -> Spec
forall a b. (a -> b) -> a -> b
$
      \ (Sz ix
sz :: Sz ix) Sz Int
i -> Sz ix -> Dim -> Sz Int -> IO (Sz ix)
forall (m :: * -> *) ix.
(MonadThrow m, Index ix) =>
Sz ix -> Dim -> Sz Int -> m (Sz ix)
setSzM Sz ix
sz Dim
1 Sz Int
i IO (Sz ix) -> Sz ix -> Expectation
forall a. (HasCallStack, Show a, Eq a) => IO a -> a -> Expectation
`shouldReturn` Sz (Lower ix) -> Sz Int -> Sz ix
forall ix. Index ix => Sz (Lower ix) -> Sz Int -> Sz ix
snocSz ((Sz (Lower ix), Sz Int) -> Sz (Lower ix)
forall a b. (a, b) -> a
fst ((Sz (Lower ix), Sz Int) -> Sz (Lower ix))
-> (Sz (Lower ix), Sz Int) -> Sz (Lower ix)
forall a b. (a -> b) -> a -> b
$ Sz ix -> (Sz (Lower ix), Sz Int)
forall ix. Index ix => Sz ix -> (Sz (Lower ix), Sz Int)
unsnocSz Sz ix
sz) Sz Int
i
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Number of Elements" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"TotalElem" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(Sz ix
sz :: Sz ix) -> Sz ix -> Int
forall ix. Index ix => Sz ix -> Int
totalElem Sz ix
sz Int -> Int -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Int -> Int -> Int) -> Int -> ix -> Int
forall ix a. Index ix => (a -> Int -> a) -> a -> ix -> a
foldlIndex Int -> Int -> Int
forall a. Num a => a -> a -> a
(*) Int
1 (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz)
    String -> (Sz ix -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"IsNonZeroSz" ((Sz ix -> Property) -> Spec) -> (Sz ix -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$
      \(Sz ix
sz :: Sz ix) -> Sz ix -> Bool
forall ix. Index ix => Sz ix -> Bool
isNotZeroSz Sz ix
sz Bool -> Bool -> Property
forall a. (Eq a, Show a) => a -> a -> Property
=== (Bool -> Int -> Bool) -> Bool -> ix -> Bool
forall ix a. Index ix => (a -> Int -> a) -> a -> ix -> a
foldlIndex (\Bool
a Int
x -> Bool
a Bool -> Bool -> Bool
&& Int
x Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0) Bool
True (Sz ix -> ix
forall ix. Sz ix -> ix
unSz Sz ix
sz)
  String -> Spec -> Spec
forall a. HasCallStack => String -> SpecWith a -> SpecWith a
describe String
"Iterators" (Spec -> Spec) -> Spec -> Spec
forall a b. (a -> b) -> a -> b
$ do
    String
-> (Sz ix -> NonNegative Int -> Positive Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"IterLinearM" ((Sz ix -> NonNegative Int -> Positive Int -> Property) -> Spec)
-> (Sz ix -> NonNegative Int -> Positive Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => Sz ix -> NonNegative Int -> Positive Int -> Property
forall ix.
Index ix =>
Sz ix -> NonNegative Int -> Positive Int -> Property
prop_IterLinearM @ix
    String
-> (Sz ix -> NonNegative Int -> Positive Int -> Property) -> Spec
forall prop.
(HasCallStack, Testable prop) =>
String -> prop -> Spec
prop String
"IterLinearM_" ((Sz ix -> NonNegative Int -> Positive Int -> Property) -> Spec)
-> (Sz ix -> NonNegative Int -> Positive Int -> Property) -> Spec
forall a b. (a -> b) -> a -> b
$ Index ix => Sz ix -> NonNegative Int -> Positive Int -> Property
forall ix.
Index ix =>
Sz ix -> NonNegative Int -> Positive Int -> Property
prop_IterLinearM_ @ix