44 lines
1.8 KiB
Haskell
44 lines
1.8 KiB
Haskell
import Test.QuickCheck
|
||
import Lib
|
||
|
||
-- Если два числа равны по модулю, то их разность делится на модуль
|
||
propCongruentDifference :: Int -> Int -> Int -> Property
|
||
propCongruentDifference a b m =
|
||
m /= 0 ==> isCongruent a b m == ((a - b) `mod` m == 0)
|
||
|
||
-- Равенство по модулю является симметричным
|
||
propCongruentSymmetric :: Int -> Int -> Int -> Property
|
||
propCongruentSymmetric a b m =
|
||
m /= 0 ==> isCongruent a b m == isCongruent b a m
|
||
|
||
-- Если одно число равно другому, то они равны по любому модулю
|
||
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
|
||
|
||
-- Если предикат всегда возвращает True, то результат совпадает с исходным списком
|
||
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
|