Created
May 7, 2016 15:54
-
-
Save nmdanny/8945b8718104a34dc3106e7cdaf5bc79 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
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE TypeFamilies #-} | |
import Test.QuickCheck | |
import JoinList | |
import Sized | |
-- Safe index, like !! for lists. | |
(!!?) :: [a] -> Int -> Maybe a | |
[] !!? i = Nothing | |
_ !!? i | i <0 = Nothing | |
(x:xs) !!? 0 = Just x | |
(x:xs) !!? i = xs !!? (i-1) | |
prop_jl_eq_list :: (Eq a,Arbitrary a) => [a] -> Bool | |
prop_jl_eq_list xs = xs == jlToList (listToJL xs) | |
prop_listIndex_eq_jlIndex :: (Eq a,Arbitrary a) => Int -> JoinList Size a -> Bool | |
prop_listIndex_eq_jlIndex i jl = (indexJ i jl) == (jlToList jl !!? i) | |
main :: IO () | |
main = do | |
putStrLn "Beginning tests." | |
quickCheck prop_jl_eq_list | |
quickCheck prop_listIndex_eq_jlIndex | |
putStrLn "All tests finished." | |
instance Arbitrary Size where | |
arbitrary = Size <$> arbitrary | |
instance (Arbitrary a) => Arbitrary (JoinList Size a) where | |
arbitrary = listToJL `fmap` arbitrary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment