Files
functional-programming/lab4/test/Spec.hs
2024-12-05 19:20:41 +03:00

44 lines
1.8 KiB
Haskell
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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