From 5bb2754dfdd3c5a1d795b286ed5d762375e10752 Mon Sep 17 00:00:00 2001 From: totycro Date: Tue, 29 May 2012 21:32:15 +0200 Subject: quickcheck --- AufgabeFFP8.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/AufgabeFFP8.hs b/AufgabeFFP8.hs index e667654..f6d9bfd 100644 --- a/AufgabeFFP8.hs +++ b/AufgabeFFP8.hs @@ -82,6 +82,16 @@ minfrom_o a (n, xs) m = length us +-- from slide 154 +divideAndConquer :: (p -> Bool) -> (p -> s) -> (p -> [p]) -> (p -> [s] -> s) -> p -> s +divideAndConquer indiv solve divide combine initPb = dAC initPb + where + dAC pb + | indiv pb = solve pb + | otherwise = combine pb (map dAC (divide pb)) + + + -- basic divide-and-conquer mittels higher order function --minfree_bhof :: [Int] -> Int @@ -94,3 +104,32 @@ minfrom_o a (n, xs) -- QuickCheck part + +functions = [ minfree_bv, minfree_chl, minfree_col, + minfree_b, minfree_r, minfree_o ] + +-- calc values of all function +calc_all :: [Int] -> [Int] +calc_all xs = [ f xs | f <- functions ] + +-- check if all values of a list are the same +all_eq :: [Int] -> Bool +all_eq (x:[]) = True +all_eq (x:y:xs) + | x == y = all_eq (y:xs) + | otherwise = False + +-- check if a list contains no duplicates +--no_dups :: [Int] -> Bool +--no_dups [] = True +--no_dups (x:xs) +-- | x `elem` xs = False +-- | otherwise = no_dups xs + +prop_allImplsEq_a :: [Int] -> Bool +prop_allImplsEq_a xs = all_eq $ calc_all (nub xs) + +-- keine negativen listenelemented durch vorbedingung entfernt +prop_allImplsEq_b :: [Int] -> Property +prop_allImplsEq_b xs = all (>=0) xs ==> all_eq $ calc_all (nub xs) + -- cgit v1.2.3