Skip to content

Commit

Permalink
quicksort quickcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-know-it-all committed Jun 23, 2019
1 parent 2302a4d commit 0c4f545
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions quickcheck-by-example/quicksort.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Test.QuickCheck
import Data.List

quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = quicksort small ++ [x] ++ quicksort large
where
small = filter (<x) xs
large = filter (>=x) xs

isSorted :: Ord a => [a] -> Bool
isSorted [] = True
isSorted [x] = True
isSorted (x:y:xs) = x <= y && isSorted xs

idempotent_property xs = quicksort (quicksort xs) == quicksort xs
sorted_pproperty xs = isSorted (quicksort xs)

main = do
quickCheck (idempotent_property :: [Integer] -> Bool)
quickCheck (sorted_pproperty :: [Integer] -> Bool)

0 comments on commit 0c4f545

Please sign in to comment.