module Tests.Mode (tests) where import Distribution.TestSuite.QuickCheck import Passman.Core.Mode import Test.QuickCheck import Control.Applicative import Data.List import Data.Maybe tests :: IO [Test] tests = return [ testProperty "prop_showReadMode" prop_showReadMode , testProperty "prop_showReadInstance" prop_showReadInstance , testProperty "prop_splitModeDistributive" prop_splitModeDistributive , testProperty "prop_splitToSingletons" prop_splitToSingletons , testProperty "prop_splitCombine" prop_splitCombine , testProperty "prop_semigroupMode" prop_semigroupMode , testProperty "prop_combineSame" prop_combineSame ] instance Arbitrary Mode where arbitrary = elements validModes shrink x = catMaybes $ do single <- [modeS, modeN, modeC, modeL] return (x <-> single) prop_showReadMode :: Mode -> Bool prop_showReadMode x = readModeMay (show x) == Just x prop_showReadInstance :: Mode -> Bool prop_showReadInstance x = read (show x) == x prop_splitModeDistributive :: Mode -> Mode -> Bool prop_splitModeDistributive x y = listEqDuplicates (splitMode (x <+> y)) (splitMode x ++ splitMode y) listEqDuplicates :: Eq a => [a] -> [a] -> Bool listEqDuplicates xs ys = all (`elem` xs) ys && all (`elem` ys) xs prop_splitToSingletons :: Mode -> Bool prop_splitToSingletons = all (`elem` [modeS, modeN, modeC, modeL]) . splitMode prop_splitCombine :: Mode -> Bool prop_splitCombine x = Just x == combineModes (splitMode x) prop_semigroupMode :: Mode -> Mode -> Mode -> Bool prop_semigroupMode x y z = (x <+> y) <+> z == x <+> (y <+> z) prop_combineSame :: Mode -> Bool prop_combineSame x = x == (x <+> x)