more quickcheck learning, just gonna go for it now
This commit is contained in:
parent
6c4c84e7dc
commit
f484da2308
@ -4,6 +4,7 @@ module LearnQuickCheck where
|
|||||||
|
|
||||||
import Test.QuickCheck
|
import Test.QuickCheck
|
||||||
import Data.List (sort)
|
import Data.List (sort)
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
qsort :: Ord a => [a] -> [a]
|
qsort :: Ord a => [a] -> [a]
|
||||||
qsort = sort
|
qsort = sort
|
||||||
@ -109,26 +110,46 @@ prop_bananas f =
|
|||||||
applyFun f "banana" == applyFun f "elephant" ||
|
applyFun f "banana" == applyFun f "elephant" ||
|
||||||
applyFun f "monkey" == applyFun f "elephant"
|
applyFun f "monkey" == applyFun f "elephant"
|
||||||
|
|
||||||
main :: IO ()
|
-- main :: IO ()
|
||||||
main = do
|
-- main = do
|
||||||
quickCheck prop_dist35
|
-- quickCheck prop_dist35
|
||||||
quickCheck prop_dist_self
|
-- quickCheck prop_dist_self
|
||||||
quickCheck prop_dist_symmetric
|
-- quickCheck prop_dist_symmetric
|
||||||
-- Roundtrip tests
|
-- -- Roundtrip tests
|
||||||
quickCheck prop_insert_delete
|
-- quickCheck prop_insert_delete
|
||||||
-- Equivalent tests
|
-- -- Equivalent tests
|
||||||
quickCheck prop_qsort_sort
|
-- quickCheck prop_qsort_sort
|
||||||
-- quickCheck prop_qsort_sort'
|
-- -- quickCheck prop_qsort_sort'
|
||||||
-- Algebraic tests
|
-- -- Algebraic tests
|
||||||
quickCheck prop_vAdd_commutative
|
-- quickCheck prop_vAdd_commutative
|
||||||
quickCheck prop_vAdd_associative
|
-- quickCheck prop_vAdd_associative
|
||||||
quickCheck prop_vAdd_neutral_left
|
-- quickCheck prop_vAdd_neutral_left
|
||||||
quickCheck prop_vAdd_neutral_right
|
-- quickCheck prop_vAdd_neutral_right
|
||||||
-- Testing with different distributions
|
-- -- Testing with different distributions
|
||||||
quickCheck prop_replicate
|
-- quickCheck prop_replicate
|
||||||
quickCheck prop_insert_sorted
|
-- quickCheck prop_insert_sorted
|
||||||
-- Quantified Properties
|
-- -- Quantified Properties
|
||||||
quickCheck prop_insert_sorted'
|
-- quickCheck prop_insert_sorted'
|
||||||
-- Testing properties of functions
|
-- -- Testing properties of functions
|
||||||
quickCheck prop_filter
|
-- quickCheck prop_filter
|
||||||
quickCheck prop_bananas
|
-- quickCheck prop_bananas
|
||||||
|
|
||||||
|
-- This next section is from the Practical Property Testing video on youtube
|
||||||
|
-- by FP Complete Corporation
|
||||||
|
|
||||||
|
genSuit, genVal :: Gen Char
|
||||||
|
genSuit = elements "HDCS"
|
||||||
|
genVal = elements "123456789JQK"
|
||||||
|
|
||||||
|
-- Applicative so can do this
|
||||||
|
genCard :: Gen (Char, Char)
|
||||||
|
genCard = (,) <$> genSuit <*> genVal
|
||||||
|
|
||||||
|
-- Monad so can do this
|
||||||
|
genCards :: Gen [(Char, Char)]
|
||||||
|
genCards = do
|
||||||
|
l <- arbitrary
|
||||||
|
replicateM l genCard
|
||||||
|
|
||||||
|
genListOf15Ints :: Gen [Int]
|
||||||
|
genListOf15Ints = resize 15 $ sized $ \n -> replicateM n arbitrary
|
||||||
|
Loading…
x
Reference in New Issue
Block a user