Created
May 8, 2010 11:32
-
-
Save proppy/394513 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Test.QuickCheck | |
myFirst :: [x] -> x | |
myFirst (x:xs) = x | |
prop_myFirst xs = not (null xs) ==> myFirst xs == head xs | |
myLast :: [x] -> x | |
myLast [x] = x | |
myLast (x:xs) = myLast xs | |
prop_myLast xs = not (null xs) ==> myLast xs == last xs | |
myButLast :: [x] -> x | |
myButLast [x,_] = x | |
myButLast (x:xs) = myButLast xs | |
prop_myButLast xs = not (null xs) && not (null (tail xs)) ==> myButLast xs == last (init xs) | |
elementAt :: [x] -> Int -> x | |
elementAt (x:xs) 1 = x | |
elementAt (x:xs) n = elementAt xs (n-1) | |
prop_elementAt xs = not (null xs) ==> and (zipWith (==) (map (elementAt xs) [1..]) xs) == True -- roconnor | |
myLength :: [x] -> Int | |
myLength [] = 0 | |
myLength (x:xs) = 1 + myLength xs | |
prop_myLength xs = myLength xs == length xs | |
myReverse :: [x] -> [x] | |
myReverse [] = [] | |
myReverse (x:xs) = myReverse xs ++ [x] | |
prop_myReverse xs = myReverse xs == reverse xs where types = (xs :: [Int]) | |
isPalindrome :: Eq a => [a] -> Bool | |
isPalindrome [] = True | |
isPalindrome [x] = True | |
isPalindrome (x:xs) = (x == (last xs)) && isPalindrome (init xs) | |
prop_isPalindrome xs = isPalindrome xs == (xs == reverse xs) where types = (xs :: [Char]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment