module ADP.Fusion.QuickCheck.Set where
import Data.Bits
import Data.Vector.Fusion.Util
import Debug.Trace
import qualified Data.List as L
import qualified Data.Vector.Fusion.Stream as S
import qualified Data.Vector.Unboxed as VU
import Test.QuickCheck hiding (NonEmpty)
import Test.QuickCheck.All
import Test.QuickCheck.Monadic
import Data.Bits.Ordered
import Data.PrimitiveArray
import ADP.Fusion
import ADP.Fusion.QuickCheck.Common
prop_b_ii ix@(BitSet _) = zs == ls where
tia = ITbl 0 0 EmptyOk xsB (\ _ _ -> Id 1)
tib = ITbl 0 0 EmptyOk xsB (\ _ _ -> Id 1)
zs = ((,) <<< tia % tib ... S.toList) highestB ix
ls = [ ( xsB ! kk , xsB ! (ix `xor` kk) )
| k <- VU.toList . popCntSorted $ popCount ix
, let kk = popShiftL ix (BitSet k)
]
prop_b_ii_nn ix@(BitSet _) = zs == ls where
tia = ITbl 0 0 NonEmpty xsB (\ _ _ -> Id 1)
tib = ITbl 0 0 NonEmpty xsB (\ _ _ -> Id 1)
zs = ((,) <<< tia % tib ... S.toList) highestB ix
ls = [ ( xsB ! kk , xsB ! (ix `xor` kk) )
| k <- VU.toList . popCntSorted $ popCount ix
, let kk = popShiftL ix (BitSet k)
, popCount kk > 0
, popCount (ix `xor` kk) > 0
]
prop_b_iii ix@(BitSet _) = zs == ls where
tia = ITbl 0 0 EmptyOk xsB (\ _ _ -> Id 1)
tib = ITbl 0 0 EmptyOk xsB (\ _ _ -> Id 1)
tic = ITbl 0 0 EmptyOk xsB (\ _ _ -> Id 1)
zs = ((,,) <<< tia % tib % tic ... S.toList) highestB ix
ls = [ ( xsB ! kk , xsB ! ll , xsB ! mm )
| k <- VU.toList . popCntSorted $ popCount ix
, l <- VU.toList . popCntSorted $ popCount ix popCount k
, let kk = popShiftL ix (BitSet k)
, let ll = popShiftL (ix `xor` kk) (BitSet l)
, let mm = (ix `xor` (kk .|. ll))
]
prop_b_iii_nnn ix@(BitSet _) = zs == ls where
tia = ITbl 0 0 NonEmpty xsB (\ _ _ -> Id 1)
tib = ITbl 0 0 NonEmpty xsB (\ _ _ -> Id 1)
tic = ITbl 0 0 NonEmpty xsB (\ _ _ -> Id 1)
zs = ((,,) <<< tia % tib % tic ... S.toList) highestB ix
ls = [ ( xsB ! kk , xsB ! ll , xsB ! mm )
| k <- VU.toList . popCntSorted $ popCount ix
, l <- VU.toList . popCntSorted $ popCount ix popCount k
, let kk = popShiftL ix (BitSet k)
, let ll = popShiftL (ix `xor` kk) (BitSet l)
, let mm = (ix `xor` (kk .|. ll))
, popCount kk > 0, popCount ll > 0, popCount mm > 0
]
prop_bii_i :: BS2I First Last -> Bool
prop_bii_i ix@(s:>i:>j) = zs == ls where
tia = ITbl 0 0 EmptyOk xsBII (\ _ _ -> Id 1)
zs = (id <<< tia ... S.toList) highestBII ix
ls = [ xsBII ! ix ]
prop_bii_i_n :: BS2I First Last -> Bool
prop_bii_i_n ix@(s:>i:>j) = zs == ls where
tia = ITbl 0 0 NonEmpty xsBII (\ _ _ -> Id 1)
zs = (id <<< tia ... S.toList) highestBII ix
ls = [ xsBII ! ix | popCount s > 0 ]
prop_bii_e :: BS2I First Last -> Bool
prop_bii_e ix@(s:>Iter i:>Iter j) = zs == ls where
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = (id <<< e ... S.toList) highestBII ix
ls = [] :: [ (Int,Int) ]
prop_bii_ie :: BS2I First Last -> Bool
prop_bii_ie ix@(s:>i:>Iter j) = zs == ls where
tia = ITbl 0 0 EmptyOk xsBII (\ _ _ -> Id 1)
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = ((,) <<< tia % e ... S.toList) highestBII ix
ls = [ ( xsBII ! (t:>i:>(Iter k :: Interface Last)) , (k,j) )
| let t = s `clearBit` j
, k <- activeBitsL t ]
prop_bii_ie_n :: BS2I First Last -> Bool
prop_bii_ie_n ix@(s:>i:>Iter j) = zs == ls where
tia = ITbl 0 0 NonEmpty xsBII (\ _ _ -> Id 1)
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = ((,) <<< tia % e ... S.toList) highestBII ix
ls = [ ( xsBII ! (t:>i:>(Iter k :: Interface Last)) , (k,j) )
| let t = s `clearBit` j
, popCount t >= 2
, k <- activeBitsL t
, k /= getIter i
]
prop_bii_iee :: BS2I First Last -> Bool
prop_bii_iee ix@(s:>i:>Iter j) = L.sort zs == L.sort ls where
tia = ITbl 0 0 EmptyOk xsBII (\ _ _ -> Id 1)
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = ((,,) <<< tia % e % e ... S.toList) highestBII ix
ls = [ ( xsBII ! (t:>i:>kk) , (k,l) , (l,j) )
| let tmp = (s `clearBit` j)
, l <- activeBitsL tmp
, l /= getIter i
, let t = tmp `clearBit` l
, k <- activeBitsL t
, let kk = Iter k
]
prop_bii_ieee :: BS2I First Last -> Bool
prop_bii_ieee ix@(s:>i:>Iter j) = L.sort zs == L.sort ls where
tia = ITbl 0 0 EmptyOk xsBII (\ _ _ -> Id 1)
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = ((,,,) <<< tia % e % e % e ... S.toList) highestBII ix
ls = [ ( xsBII ! (t:>i:>kk) , (k,l) , (l,m) , (m,j) )
| let tmpM = (s `clearBit` j)
, m <- activeBitsL tmpM
, m /= getIter i
, let tmpL = (tmpM `clearBit` m)
, l <- activeBitsL tmpL
, l /= getIter i
, let t = tmpL `clearBit` l
, k <- activeBitsL t
, let kk = Iter k
]
prop_bii_iee_n :: BS2I First Last -> Bool
prop_bii_iee_n ix@(s:>i:>Iter j) = L.sort zs == L.sort ls where
tia = ITbl 0 0 NonEmpty xsBII (\ _ _ -> Id 1)
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = ((,,) <<< tia % e % e ... S.toList) highestBII ix
ls = [ ( xsBII ! (t:>i:>kk) , (k,l) , (l,j) )
| let tmp = (s `clearBit` j)
, l <- activeBitsL tmp
, l /= getIter i
, let t = tmp `clearBit` l
, popCount t >= 2
, k <- activeBitsL t
, k /= getIter i
, let kk = Iter k
]
prop_bii_ieee_n :: BS2I First Last -> Bool
prop_bii_ieee_n ix@(s:>i:>Iter j) = L.sort zs == L.sort ls where
tia = ITbl 0 0 NonEmpty xsBII (\ _ _ -> Id 1)
e = Edge (\ i j -> (i,j)) :: Edge (Int,Int)
zs = ((,,,) <<< tia % e % e % e ... S.toList) highestBII ix
ls = [ ( xsBII ! (t:>i:>kk) , (k,l) , (l,m) , (m,j) )
| let tmpM = (s `clearBit` j)
, m <- activeBitsL tmpM
, m /= getIter i
, let tmpL = (tmpM `clearBit` m)
, l <- activeBitsL tmpL
, l /= getIter i
, let t = tmpL `clearBit` l
, popCount t >= 2
, k <- activeBitsL t
, k /= getIter i
, let kk = Iter k
]
highBit = fromIntegral arbitraryBitSetMax
highestB = BitSet $ 2^(highBit+1) 1
highestBII = highestB :> Iter (highBit1) :> Iter (highBit1)
xsB :: Unboxed BitSet Int
xsB = fromList (BitSet 0) highestB [ 0 .. ]
xoB :: Unboxed (Outside BitSet) Int
xoB = fromList (O (BitSet 0)) (O highestB) [ 0 .. ]
xsBII :: Unboxed (BitSet:>Interface First:>Interface Last) Int
xsBII = fromList (BitSet 0:>Iter 0:>Iter 0) highestBII [ 0 .. ]
options = stdArgs {maxSuccess = 1000}
customCheck = quickCheckWithResult options
return []
allProps = $forAllProperties customCheck