packages feed

papa-0.7.0: test/PropertiesVector.hs

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}

{- HLINT ignore "Avoid restricted function" -}
-- Reason: these properties compare Papa's total head, last, init, tail,
-- maximum and minimum of vectors with vector's partial ones, whose names
-- HLint restricts whatever module they come from.

-- | The properties of the total vector, hash map and hash set modules: each
-- total function agrees with the partial one it replaces (it is 'Nothing'
-- exactly where the partial one throws), and lens's 'ix', 'at' and
-- 'contains' agree with the indexing functions.
--
-- The monadic folds are compared in 'Maybe', whose bind forces the fold: in
-- 'Identity', the originals' error for an empty vector is never forced.
module PropertiesVector (
  propertiesVector,
) where

import Agree (agrees)
import Control.Monad.ST (runST)
import qualified Data.HashMap.Strict as OHM
import qualified Data.HashSet as OHS
import qualified Data.Vector as OV
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Storable as OS
import qualified Data.Vector.Storable.Mutable as MS
import qualified Data.Vector.Unboxed as OU
import qualified Data.Vector.Unboxed.Mutable as MU
import Hedgehog (Gen, Group (Group), Property, PropertyName, forAll, property, (===))
import Hedgehog.Function (Fn, apply, fn)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import Papa
import qualified Papa.UnorderedContainers.Data.HashMap as HashMap
import qualified Papa.UnorderedContainers.Data.HashSet as HashSet
import qualified Papa.Vector.Data.Vector as PV
import qualified Papa.Vector.Data.Vector.Storable as PS
import qualified Papa.Vector.Data.Vector.Unboxed as PU

-- | The properties of the vector, hash map and hash set modules.
propertiesVector :: Group
propertiesVector =
  Group "papa: vector, unordered-containers" (vector <> unboxed <> storable <> hashMap <> hashSet)

prop :: PropertyName -> Property -> [(PropertyName, Property)]
prop name p =
  [(name, p)]

genInt :: Gen Int
genInt =
  Gen.int (Range.linear (-100) 100)

genIndex :: Gen Int
genIndex =
  Gen.int (Range.linear (-3) 12)

genList :: Gen [Int]
genList =
  Gen.list (Range.linear 0 10) genInt

genIndices :: Gen [Int]
genIndices =
  Gen.list (Range.linear 0 5) genIndex

genUpdates :: Gen [(Int, Int)]
genUpdates =
  Gen.list (Range.linear 0 5) ((,) <$> genIndex <*> genInt)

genFn1 :: Gen (Fn Int Int)
genFn1 =
  fn genInt

genFn2 :: Gen (Fn (Int, Int) Int)
genFn2 =
  fn genInt

genKey :: Gen Int
genKey =
  Gen.int (Range.linear 0 20)

genHashMap :: Gen (HashMap Int Int)
genHashMap =
  HashMap.fromList <$> Gen.list (Range.linear 0 10) ((,) <$> genKey <*> genInt)

genHashSet :: Gen (HashSet Int)
genHashSet =
  HashSet.fromList <$> Gen.list (Range.linear 0 10) genKey

genPV :: Gen (OV.Vector Int)
genPV =
  OV.fromList <$> genList

vector :: [(PropertyName, Property)]
vector =
  prop "Vector.head: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.head v) (OV.head v)))
    <> prop "Vector.last: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.last v) (OV.last v)))
    <> prop "Vector.indexM: agrees with Data.Vector" (property (do v <- forAll genPV; i <- forAll genIndex; agrees (runIdentity (PV.indexM v i)) (runIdentity (OV.indexM v i))))
    <> prop "Vector.headM: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (runIdentity (PV.headM v)) (runIdentity (OV.headM v))))
    <> prop "Vector.lastM: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (runIdentity (PV.lastM v)) (runIdentity (OV.lastM v))))
    <> prop "Vector.slice: agrees with Data.Vector" (property (do v <- forAll genPV; i <- forAll genIndex; n <- forAll genIndex; agrees (PV.slice i n v) (OV.slice i n v)))
    <> prop "Vector.init: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.init v) (OV.init v)))
    <> prop "Vector.tail: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.tail v) (OV.tail v)))
    <> prop "Vector.constructN: agrees with Data.Vector" (property (do n <- forAll genIndex; agrees (PV.constructN n (OV.sum :: OV.Vector Int -> Int)) (OV.constructN n OV.sum)))
    <> prop "Vector.constructrN: agrees with Data.Vector" (property (do n <- forAll genIndex; agrees (PV.constructrN n (OV.sum :: OV.Vector Int -> Int)) (OV.constructrN n OV.sum)))
    <> prop "Vector.//: agrees with Data.Vector" (property (do v <- forAll genPV; us <- forAll genUpdates; agrees (v PV.// us) (v OV.// us)))
    <> prop "Vector.update: agrees with Data.Vector" (property (do v <- forAll genPV; us <- forAll genUpdates; agrees (PV.update v (OV.fromList us)) (OV.update v (OV.fromList us))))
    <> prop "Vector.update_: agrees with Data.Vector" (property (do v <- forAll genPV; is <- forAll genIndices; xs <- forAll genPV; agrees (PV.update_ v (OV.fromList is) xs) (OV.update_ v (OV.fromList is) xs)))
    <> prop "Vector.accum: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; us <- forAll genUpdates; agrees (PV.accum f v us) (OV.accum f v us)))
    <> prop "Vector.accumulate: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; us <- forAll genUpdates; agrees (PV.accumulate f v (OV.fromList us)) (OV.accumulate f v (OV.fromList us))))
    <> prop "Vector.accumulate_: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; is <- forAll genIndices; xs <- forAll genPV; agrees (PV.accumulate_ f v (OV.fromList is) xs) (OV.accumulate_ f v (OV.fromList is) xs)))
    <> prop "Vector.backpermute: agrees with Data.Vector" (property (do v <- forAll genPV; is <- forAll genIndices; agrees (PV.backpermute v (OV.fromList is)) (OV.backpermute v (OV.fromList is))))
    <> prop "Vector.foldl1: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PV.foldl1 f v) (OV.foldl1 f v)))
    <> prop "Vector.foldl1': agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PV.foldl1' f v) (OV.foldl1' f v)))
    <> prop "Vector.foldr1: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PV.foldr1 f v) (OV.foldr1 f v)))
    <> prop "Vector.foldr1': agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PV.foldr1' f v) (OV.foldr1' f v)))
    <> prop "Vector.maximum: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.maximum v) (OV.maximum v)))
    <> prop "Vector.maximumBy: agrees with Data.Vector" (property (do v <- forAll genPV; h <- forAll genFn1; agrees (PV.maximumBy (comparing (apply h)) v) (OV.maximumBy (comparing (apply h)) v)))
    <> prop "Vector.maximumOn: agrees with Data.Vector" (property (do v <- forAll genPV; h <- forAll genFn1; agrees (PV.maximumOn (apply h) v) (OV.maximumOn (apply h) v)))
    <> prop "Vector.minimum: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.minimum v) (OV.minimum v)))
    <> prop "Vector.minimumBy: agrees with Data.Vector" (property (do v <- forAll genPV; h <- forAll genFn1; agrees (PV.minimumBy (comparing (apply h)) v) (OV.minimumBy (comparing (apply h)) v)))
    <> prop "Vector.minimumOn: agrees with Data.Vector" (property (do v <- forAll genPV; h <- forAll genFn1; agrees (PV.minimumOn (apply h) v) (OV.minimumOn (apply h) v)))
    <> prop "Vector.maxIndex: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.maxIndex v) (OV.maxIndex v)))
    <> prop "Vector.maxIndexBy: agrees with Data.Vector" (property (do v <- forAll genPV; h <- forAll genFn1; agrees (PV.maxIndexBy (comparing (apply h)) v) (OV.maxIndexBy (comparing (apply h)) v)))
    <> prop "Vector.minIndex: agrees with Data.Vector" (property (do v <- forAll genPV; agrees (PV.minIndex v) (OV.minIndex v)))
    <> prop "Vector.minIndexBy: agrees with Data.Vector" (property (do v <- forAll genPV; h <- forAll genFn1; agrees (PV.minIndexBy (comparing (apply h)) v) (OV.minIndexBy (comparing (apply h)) v)))
    <> prop "Vector.fold1M: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PV.fold1M f v)) (OV.fold1M f v)))
    <> prop "Vector.fold1M': agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PV.fold1M' f v)) (OV.fold1M' f v)))
    <> prop "Vector.fold1M_: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PV.fold1M_ f v)) (OV.fold1M_ f v)))
    <> prop "Vector.fold1M'_: agrees with Data.Vector" (property (do v <- forAll genPV; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PV.fold1M'_ f v)) (OV.fold1M'_ f v)))
    <> prop "Vector.copy: agrees with Data.Vector" (property (do v <- forAll genPV; n <- forAll genIndex; agrees (runST (do m <- MV.replicate (max 0 n) 0; r <- PV.copy m v; w <- OV.freeze m; pure (w <$ r))) (runST (do m <- MV.replicate (max 0 n) 0; OV.copy m v; OV.freeze m))))
    <> prop "Vector.ix: agrees with Data.Vector" (property (do v <- forAll genPV; i <- forAll genIndex; agrees (v ^? ix i) (v OV.! i)))
    <> prop "Vector.ix .~: agrees with Data.Vector" (property (do v <- forAll genPV; i <- forAll genIndex; a <- forAll genInt; (v & ix i .~ a) === fromMaybe v (v PV.// [(i, a)])))

genPU :: Gen (OU.Vector Int)
genPU =
  OU.fromList <$> genList

unboxed :: [(PropertyName, Property)]
unboxed =
  prop "Unboxed.head: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.head v) (OU.head v)))
    <> prop "Unboxed.last: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.last v) (OU.last v)))
    <> prop "Unboxed.indexM: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; i <- forAll genIndex; agrees (runIdentity (PU.indexM v i)) (runIdentity (OU.indexM v i))))
    <> prop "Unboxed.headM: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (runIdentity (PU.headM v)) (runIdentity (OU.headM v))))
    <> prop "Unboxed.lastM: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (runIdentity (PU.lastM v)) (runIdentity (OU.lastM v))))
    <> prop "Unboxed.slice: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; i <- forAll genIndex; n <- forAll genIndex; agrees (PU.slice i n v) (OU.slice i n v)))
    <> prop "Unboxed.init: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.init v) (OU.init v)))
    <> prop "Unboxed.tail: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.tail v) (OU.tail v)))
    <> prop "Unboxed.constructN: agrees with Data.Vector.Unboxed" (property (do n <- forAll genIndex; agrees (PU.constructN n (OU.sum :: OU.Vector Int -> Int)) (OU.constructN n OU.sum)))
    <> prop "Unboxed.constructrN: agrees with Data.Vector.Unboxed" (property (do n <- forAll genIndex; agrees (PU.constructrN n (OU.sum :: OU.Vector Int -> Int)) (OU.constructrN n OU.sum)))
    <> prop "Unboxed.//: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; us <- forAll genUpdates; agrees (v PU.// us) (v OU.// us)))
    <> prop "Unboxed.update: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; us <- forAll genUpdates; agrees (PU.update v (OU.fromList us)) (OU.update v (OU.fromList us))))
    <> prop "Unboxed.update_: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; is <- forAll genIndices; xs <- forAll genPU; agrees (PU.update_ v (OU.fromList is) xs) (OU.update_ v (OU.fromList is) xs)))
    <> prop "Unboxed.accum: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; us <- forAll genUpdates; agrees (PU.accum f v us) (OU.accum f v us)))
    <> prop "Unboxed.accumulate: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; us <- forAll genUpdates; agrees (PU.accumulate f v (OU.fromList us)) (OU.accumulate f v (OU.fromList us))))
    <> prop "Unboxed.accumulate_: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; is <- forAll genIndices; xs <- forAll genPU; agrees (PU.accumulate_ f v (OU.fromList is) xs) (OU.accumulate_ f v (OU.fromList is) xs)))
    <> prop "Unboxed.backpermute: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; is <- forAll genIndices; agrees (PU.backpermute v (OU.fromList is)) (OU.backpermute v (OU.fromList is))))
    <> prop "Unboxed.foldl1: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PU.foldl1 f v) (OU.foldl1 f v)))
    <> prop "Unboxed.foldl1': agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PU.foldl1' f v) (OU.foldl1' f v)))
    <> prop "Unboxed.foldr1: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PU.foldr1 f v) (OU.foldr1 f v)))
    <> prop "Unboxed.foldr1': agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PU.foldr1' f v) (OU.foldr1' f v)))
    <> prop "Unboxed.maximum: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.maximum v) (OU.maximum v)))
    <> prop "Unboxed.maximumBy: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; h <- forAll genFn1; agrees (PU.maximumBy (comparing (apply h)) v) (OU.maximumBy (comparing (apply h)) v)))
    <> prop "Unboxed.maximumOn: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; h <- forAll genFn1; agrees (PU.maximumOn (apply h) v) (OU.maximumOn (apply h) v)))
    <> prop "Unboxed.minimum: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.minimum v) (OU.minimum v)))
    <> prop "Unboxed.minimumBy: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; h <- forAll genFn1; agrees (PU.minimumBy (comparing (apply h)) v) (OU.minimumBy (comparing (apply h)) v)))
    <> prop "Unboxed.minimumOn: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; h <- forAll genFn1; agrees (PU.minimumOn (apply h) v) (OU.minimumOn (apply h) v)))
    <> prop "Unboxed.maxIndex: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.maxIndex v) (OU.maxIndex v)))
    <> prop "Unboxed.maxIndexBy: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; h <- forAll genFn1; agrees (PU.maxIndexBy (comparing (apply h)) v) (OU.maxIndexBy (comparing (apply h)) v)))
    <> prop "Unboxed.minIndex: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; agrees (PU.minIndex v) (OU.minIndex v)))
    <> prop "Unboxed.minIndexBy: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; h <- forAll genFn1; agrees (PU.minIndexBy (comparing (apply h)) v) (OU.minIndexBy (comparing (apply h)) v)))
    <> prop "Unboxed.fold1M: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PU.fold1M f v)) (OU.fold1M f v)))
    <> prop "Unboxed.fold1M': agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PU.fold1M' f v)) (OU.fold1M' f v)))
    <> prop "Unboxed.fold1M_: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PU.fold1M_ f v)) (OU.fold1M_ f v)))
    <> prop "Unboxed.fold1M'_: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PU.fold1M'_ f v)) (OU.fold1M'_ f v)))
    <> prop "Unboxed.copy: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; n <- forAll genIndex; agrees (runST (do m <- MU.replicate (max 0 n) 0; r <- PU.copy m v; w <- OU.freeze m; pure (w <$ r))) (runST (do m <- MU.replicate (max 0 n) 0; OU.copy m v; OU.freeze m))))
    <> prop "Unboxed.ix: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; i <- forAll genIndex; agrees (v ^? ix i) (v OU.! i)))
    <> prop "Unboxed.ix .~: agrees with Data.Vector.Unboxed" (property (do v <- forAll genPU; i <- forAll genIndex; a <- forAll genInt; (v & ix i .~ a) === fromMaybe v (v PU.// [(i, a)])))

genPS :: Gen (OS.Vector Int)
genPS =
  OS.fromList <$> genList

storable :: [(PropertyName, Property)]
storable =
  prop "Storable.head: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.head v) (OS.head v)))
    <> prop "Storable.last: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.last v) (OS.last v)))
    <> prop "Storable.indexM: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; i <- forAll genIndex; agrees (runIdentity (PS.indexM v i)) (runIdentity (OS.indexM v i))))
    <> prop "Storable.headM: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (runIdentity (PS.headM v)) (runIdentity (OS.headM v))))
    <> prop "Storable.lastM: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (runIdentity (PS.lastM v)) (runIdentity (OS.lastM v))))
    <> prop "Storable.slice: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; i <- forAll genIndex; n <- forAll genIndex; agrees (PS.slice i n v) (OS.slice i n v)))
    <> prop "Storable.init: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.init v) (OS.init v)))
    <> prop "Storable.tail: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.tail v) (OS.tail v)))
    <> prop "Storable.constructN: agrees with Data.Vector.Storable" (property (do n <- forAll genIndex; agrees (PS.constructN n (OS.sum :: OS.Vector Int -> Int)) (OS.constructN n OS.sum)))
    <> prop "Storable.constructrN: agrees with Data.Vector.Storable" (property (do n <- forAll genIndex; agrees (PS.constructrN n (OS.sum :: OS.Vector Int -> Int)) (OS.constructrN n OS.sum)))
    <> prop "Storable.//: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; us <- forAll genUpdates; agrees (v PS.// us) (v OS.// us)))
    <> prop "Storable.update_: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; is <- forAll genIndices; xs <- forAll genPS; agrees (PS.update_ v (OS.fromList is) xs) (OS.update_ v (OS.fromList is) xs)))
    <> prop "Storable.accum: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = apply g (a, b) }; us <- forAll genUpdates; agrees (PS.accum f v us) (OS.accum f v us)))
    <> prop "Storable.accumulate_: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = apply g (a, b) }; is <- forAll genIndices; xs <- forAll genPS; agrees (PS.accumulate_ f v (OS.fromList is) xs) (OS.accumulate_ f v (OS.fromList is) xs)))
    <> prop "Storable.backpermute: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; is <- forAll genIndices; agrees (PS.backpermute v (OS.fromList is)) (OS.backpermute v (OS.fromList is))))
    <> prop "Storable.foldl1: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PS.foldl1 f v) (OS.foldl1 f v)))
    <> prop "Storable.foldl1': agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PS.foldl1' f v) (OS.foldl1' f v)))
    <> prop "Storable.foldr1: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PS.foldr1 f v) (OS.foldr1 f v)))
    <> prop "Storable.foldr1': agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = apply g (a, b) }; agrees (PS.foldr1' f v) (OS.foldr1' f v)))
    <> prop "Storable.maximum: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.maximum v) (OS.maximum v)))
    <> prop "Storable.maximumBy: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; h <- forAll genFn1; agrees (PS.maximumBy (comparing (apply h)) v) (OS.maximumBy (comparing (apply h)) v)))
    <> prop "Storable.maximumOn: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; h <- forAll genFn1; agrees (PS.maximumOn (apply h) v) (OS.maximumOn (apply h) v)))
    <> prop "Storable.minimum: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.minimum v) (OS.minimum v)))
    <> prop "Storable.minimumBy: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; h <- forAll genFn1; agrees (PS.minimumBy (comparing (apply h)) v) (OS.minimumBy (comparing (apply h)) v)))
    <> prop "Storable.minimumOn: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; h <- forAll genFn1; agrees (PS.minimumOn (apply h) v) (OS.minimumOn (apply h) v)))
    <> prop "Storable.maxIndex: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.maxIndex v) (OS.maxIndex v)))
    <> prop "Storable.maxIndexBy: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; h <- forAll genFn1; agrees (PS.maxIndexBy (comparing (apply h)) v) (OS.maxIndexBy (comparing (apply h)) v)))
    <> prop "Storable.minIndex: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; agrees (PS.minIndex v) (OS.minIndex v)))
    <> prop "Storable.minIndexBy: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; h <- forAll genFn1; agrees (PS.minIndexBy (comparing (apply h)) v) (OS.minIndexBy (comparing (apply h)) v)))
    <> prop "Storable.fold1M: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PS.fold1M f v)) (OS.fold1M f v)))
    <> prop "Storable.fold1M': agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PS.fold1M' f v)) (OS.fold1M' f v)))
    <> prop "Storable.fold1M_: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PS.fold1M_ f v)) (OS.fold1M_ f v)))
    <> prop "Storable.fold1M'_: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; g <- forAll genFn2; let { f a b = Just (apply g (a, b)) }; agrees (sequenceA (PS.fold1M'_ f v)) (OS.fold1M'_ f v)))
    <> prop "Storable.copy: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; n <- forAll genIndex; agrees (runST (do m <- MS.replicate (max 0 n) 0; r <- PS.copy m v; w <- OS.freeze m; pure (w <$ r))) (runST (do m <- MS.replicate (max 0 n) 0; OS.copy m v; OS.freeze m))))
    <> prop "Storable.ix: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; i <- forAll genIndex; agrees (v ^? ix i) (v OS.! i)))
    <> prop "Storable.ix .~: agrees with Data.Vector.Storable" (property (do v <- forAll genPS; i <- forAll genIndex; a <- forAll genInt; (v & ix i .~ a) === fromMaybe v (v PS.// [(i, a)])))

hashMap :: [(PropertyName, Property)]
hashMap =
  prop "HashMap ix: agrees with Data.HashMap.Strict.!" (property (do m <- forAll genHashMap; k <- forAll genKey; agrees (m ^? ix k) (m OHM.! k)))
    <> prop "HashMap at: lookup" (property (do m <- forAll genHashMap; k <- forAll genKey; the (at k) m === OHM.lookup k m))
    <> prop "HashMap at ?~: insert" (property (do m <- forAll genHashMap; k <- forAll genKey; a <- forAll genInt; (m & at k ?~ a) === OHM.insert k a m))
    <> prop "HashMap sans (at .~ Nothing): delete" (property (do m <- forAll genHashMap; k <- forAll genKey; sans k m === OHM.delete k m))
    <> prop "HashMap ix %~: adjust" (property (do m <- forAll genHashMap; k <- forAll genKey; h <- forAll genFn1; (m & ix k %~ apply h) === OHM.adjust (apply h) k m))

hashSet :: [(PropertyName, Property)]
hashSet =
  prop "HashSet contains: member" (property (do s <- forAll genHashSet; a <- forAll genKey; the (contains a) s === OHS.member a s))
    <> prop "HashSet contains .~ True: insert" (property (do s <- forAll genHashSet; a <- forAll genKey; (s & contains a .~ True) === OHS.insert a s))
    <> prop "HashSet contains .~ False: delete" (property (do s <- forAll genHashSet; a <- forAll genKey; (s & contains a .~ False) === OHS.delete a s))