Skip to content

Instantly share code, notes, and snippets.

@nmdanny
Created May 7, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmdanny/8945b8718104a34dc3106e7cdaf5bc79 to your computer and use it in GitHub Desktop.
Save nmdanny/8945b8718104a34dc3106e7cdaf5bc79 to your computer and use it in GitHub Desktop.
{-# 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