From a3061e6678625a3087c969b4c3f1663cf3c4aea8 Mon Sep 17 00:00:00 2001 From: Arity-T Date: Fri, 29 Nov 2024 20:00:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20filterByPredicate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab4/test/Spec.hs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lab4/test/Spec.hs b/lab4/test/Spec.hs index 360ec28..ab58924 100644 --- a/lab4/test/Spec.hs +++ b/lab4/test/Spec.hs @@ -1,5 +1,5 @@ import Test.QuickCheck -import Lib (isCongruent) +import Lib propCongruentDifference :: Int -> Int -> Int -> Property propCongruentDifference a b m = @@ -13,8 +13,25 @@ propCongruentEqualNumbers :: Int -> Int -> Property propCongruentEqualNumbers a m = m /= 0 ==> isCongruent a a m == True + +propFilterByPredicateSatisfiesPredicate :: Fun Int Bool -> [Int] -> Bool +propFilterByPredicateSatisfiesPredicate (Fun _ predicate) xs = + all predicate (filterByPredicate predicate xs) + +propFilterByPredicateLength :: Fun Int Bool -> [Int] -> Bool +propFilterByPredicateLength (Fun _ predicate) xs = + length (filterByPredicate predicate xs) <= length xs + +propFilterByPredicateAlwaysTrue :: [Int] -> Bool +propFilterByPredicateAlwaysTrue xs = + filterByPredicate (\_ -> True) xs == xs + main :: IO () main = do quickCheck propCongruentDifference quickCheck propCongruentSymmetric quickCheck propCongruentEqualNumbers + + quickCheck propFilterByPredicateSatisfiesPredicate + quickCheck propFilterByPredicateLength + quickCheck propFilterByPredicateAlwaysTrue