import Test.QuickCheck import Control.Arrow (second) import Control.Monad import Data.Word import qualified Data.Rope as R import qualified Data.ByteString as B import System.Environment (getArgs) import Text.Printf (printf) import QuickCheckUtils -- -- Rope <=> ByteString -- -- prop_isBalanced r = R.isBalanced (R.balance r) prop_lengthBP = R.length `eq1` (fromIntegral . B.length :: B.ByteString -> Int) prop_concatBP = R.concat `eq1` B.concat --prop_nullBP = R.null `eq1` B.null --prop_reverseBP = R.reverse `eq1` B.reverse --prop_transposeBP = R.transpose `eq1` B.transpose --prop_groupBP = R.group `eq1` B.group --prop_initsBP = R.inits `eq1` B.inits --prop_tailsBP = R.tails `eq1` B.tails --prop_allBP = R.all `eq2` B.all --prop_anyBP = R.any `eq2` B.any --prop_appendBP = R.append `eq2` B.append --prop_breakBP = R.break `eq2` B.break --prop_concatMapBP = R.concatMap `eq2` B.concatMap --prop_consBP = R.cons `eq2` B.cons --prop_countBP = R.count `eq2` B.count --prop_dropBP = R.drop `eq2` B.drop --prop_dropWhileBP = R.dropWhile `eq2` B.dropWhile --prop_filterBP = R.filter `eq2` B.filter --prop_findBP = R.find `eq2` B.find --prop_findIndexBP = R.findIndex `eq2` B.findIndex --prop_findIndicesBP = R.findIndices `eq2` B.findIndices --prop_isPrefixOfBP = R.isPrefixOf `eq2` B.isPrefixOf --prop_mapBP = R.map `eq2` B.map --prop_replicateBP = R.replicate `eq2` B.replicate --prop_snocBP = R.snoc `eq2` B.snoc --prop_spanBP = R.span `eq2` B.span --prop_splitBP = R.split `eq2` B.split --prop_splitAtBP = R.splitAt `eq2` B.splitAt --prop_takeBP = R.take `eq2` B.take --prop_takeWhileBP = R.takeWhile `eq2` B.takeWhile --prop_elemBP = R.elem `eq2` B.elem --prop_notElemBP = R.notElem `eq2` B.notElem --prop_elemIndexBP = R.elemIndex `eq2` B.elemIndex --prop_elemIndicesBP = R.elemIndices `eq2` B.elemIndices --prop_readIntBP = R.readInt `eq1` B.readInt --prop_linesBP = R.lines `eq1` B.lines --prop_headBP = L.head `eqnotnull1` P.head --prop_initBP = L.init `eqnotnull1` P.init --prop_lastBP = L.last `eqnotnull1` P.last --prop_maximumBP = L.maximum `eqnotnull1` P.maximum --prop_minimumBP = L.minimum `eqnotnull1` P.minimum --prop_tailBP = L.tail `eqnotnull1` P.tail --prop_foldl1BP = L.foldl1 `eqnotnull2` P.foldl1 --prop_foldl1BP' = L.foldl1' `eqnotnull2` P.foldl1' --prop_foldr1BP = L.foldr1 `eqnotnull2` P.foldr1 --prop_scanlBP = L.scanl `eqnotnull3` P.scanl bp_tests = [ ("balancing", mytest prop_isBalanced), -- ("all", mytest prop_allBP) -- ,("any", mytest prop_anyBP) -- ,("append", mytest prop_appendBP) -- ,("compare", mytest prop_compareBP) ("concat", mytest prop_concatBP) -- ,("cons", mytest prop_consBP) -- ,("eq", mytest prop_eqBP) -- ,("filter", mytest prop_filterBP) -- ,("find", mytest prop_findBP) -- ,("findIndex", mytest prop_findIndexBP) -- ,("findIndices", mytest prop_findIndicesBP) -- ,("foldl", mytest prop_foldlBP) -- ,("foldl'", mytest prop_foldlBP') -- ,("foldl1", mytest prop_foldl1BP) -- ,("foldl1'", mytest prop_foldl1BP') -- ,("foldr", mytest prop_foldrBP) -- ,("foldr1", mytest prop_foldr1BP) -- ,("mapAccumL", mytest prop_mapAccumLBP) -- ,("unfoldr", mytest prop_unfoldrBP) -- ,("head", mytest prop_headBP) -- ,("init", mytest prop_initBP) -- ,("isPrefixOf", mytest prop_isPrefixOfBP) -- ,("last", mytest prop_lastBP) ,("length", mytest prop_lengthBP) -- ,("readInt", mytest prop_readIntBP) -- ,("lines", mytest prop_linesBP) -- ,("lines \\n", mytest prop_linesNLBP) -- ,("map", mytest prop_mapBP) -- ,("maximum ", mytest prop_maximumBP) -- ,("minimum" , mytest prop_minimumBP) -- ,("null", mytest prop_nullBP) -- ,("reverse", mytest prop_reverseBP) -- ,("snoc", mytest prop_snocBP) -- ,("tail", mytest prop_tailBP) -- ,("scanl", mytest prop_scanlBP) -- ,("transpose", mytest prop_transposeBP) -- ,("replicate", mytest prop_replicateBP) -- ,("take", mytest prop_takeBP) -- ,("drop", mytest prop_dropBP) -- ,("splitAt", mytest prop_splitAtBP) -- ,("takeWhile", mytest prop_takeWhileBP) -- ,("dropWhile", mytest prop_dropWhileBP) -- ,("break", mytest prop_breakBP) -- ,("span", mytest prop_spanBP) -- ,("split", mytest prop_splitBP) -- ,("count", mytest prop_countBP) -- ,("group", mytest prop_groupBP) -- ,("inits", mytest prop_initsBP) -- ,("tails", mytest prop_tailsBP) -- ,("elem", mytest prop_elemBP) -- ,("notElem", mytest prop_notElemBP) -- ,("elemIndex", mytest prop_elemIndexBP) -- ,("elemIndices", mytest prop_elemIndicesBP) -- ,("concatMap", mytest prop_concatMapBP) ] tests = bp_tests main = run tests run :: [(String, Int -> IO ())] -> IO () run tests = do x <- getArgs let n = if null x then 100 else read . head $ x mapM_ (\(s,a) -> printf "%-25s: " s >> a n) tests {- instance Show R.Rope where show = show . R.flatten -} instance Arbitrary R.Rope where arbitrary = oneof [return R.Empty, sized arb] where genLeaf = liftM R.Leaf (do bs <- arbitrary :: Gen B.ByteString b <- arbitrary :: Gen Word8 return $ b `B.cons` bs ) arb 0 = genLeaf arb n = frequency $ map (second $ resize (n `div` 2)) [ (2, genLeaf), (2, do leftTree <- sized arb :: Gen R.Rope rightTree <- sized arb :: Gen R.Rope let l = R.length leftTree + R.length rightTree let d = 1 + max (R.depth leftTree) (R.depth rightTree) return (R.Node l d leftTree rightTree) ) ] coarbitrary = undefined