packages feed

hw-balancedparens-0.4.1.0: test/HaskellWorks/Data/BalancedParens/Internal/Broadword/FindClose/Vector64Spec.hs

module HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64Spec
  ( spec
  ) where

import HaskellWorks.Data.Bits.BitLength
import HaskellWorks.Data.Bits.BitShow
import HaskellWorks.Hspec.Hedgehog
import Hedgehog
import Test.Hspec

import qualified Data.Vector.Storable                                                   as DVS
import qualified HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64 as V64
import qualified HaskellWorks.Data.BalancedParens.Internal.Slow.FindCloseN.Generic      as G
import qualified Hedgehog.Gen                                                           as G
import qualified Hedgehog.Range                                                         as R

{-# ANN module ("HLint: ignore Evaluate"            :: String) #-}
{-# ANN module ("HLint: ignore Reduce duplication"  :: String) #-}
{-# ANN module ("HLint: ignore Redundant do"        :: String) #-}

spec :: Spec
spec = describe "HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Vector64Spec" $ do
  describe "findClose" $ do
    it "Two element vector zero as second word" $ require $ withTests 1000 $ property $ do
      w   <- forAll $ G.word64 R.constantBounded
      p   <- forAll $ G.word64 (R.linear 1 (bitLength w))
      _   <- forAll $ pure $ bitShow w
      v   <- forAll $ pure $ DVS.fromList [w, 0]
      V64.findClose v p === G.findCloseN w 0 p
    it "Two element vector" $ require $ withTests 1000 $ property $ do
      w0  <- forAll $ G.word64 R.constantBounded
      w1  <- forAll $ G.word64 R.constantBounded
      p   <- forAll $ G.word64 (R.linear 1 (bitLength w0 * 2))
      v   <- forAll $ pure $ DVS.fromList [w0, w1]
      _   <- forAll $ pure $ bitShow v
      V64.findClose v p === G.findCloseN v 0 p