aboutsummaryrefslogtreecommitdiff
path: root/test/Spec.hs
blob: eeccba0396e91f23c21295f54cb2e01b4919f7d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import Lib (isCongruent, zipWithSum)
import Test.QuickCheck

-- Если два числа равны по модулю, то их разность делится на модуль:
--
-- isCongruent a b m == (modulus (a - b) m == 0)
prop_isCongruent_diffDivisible :: Int -> Int -> Int -> Property
prop_isCongruent_diffDivisible a b m =
  m /= 0 ==> isCongruent a b m == ((a - b) `mod` m == 0)

-- Равенство по модулю является симметричным:
--
-- isCongruent a b m == isCongruent b a m
prop_isCongruent_symmetry :: Int -> Int -> Int -> Property
prop_isCongruent_symmetry a b m =
  m /= 0 ==> isCongruent a b m == isCongruent b a m

-- Если одно число равно другому, то они равны по любому модулю:
--
-- если a == b, то isCongruent a b m == True
prop_isCongruent_equalAlwaysCongruent :: Int -> Int -> Property
prop_isCongruent_equalAlwaysCongruent a m = m /= 0 ==> isCongruent a a m == True

-- Длины результата равна максимальной длине входных списков:
--
-- length (zipWithSum xs ys) == max (length xs) (length ys)
prop_zipWithSum_length :: [Int] -> [Int] -> Bool
prop_zipWithSum_length xs ys =
  length (zipWithSum xs ys) == max (length xs) (length ys)

-- Если один из списков пустой, то результат совпадает с непустым
-- списком:
--
-- если xs пустой, то zipWithSum [] ys == ys
prop_zipWithSum_emptyList :: [Int] -> Bool
prop_zipWithSum_emptyList xs = zipWithSum [] xs == xs && zipWithSum xs [] == xs

-- Сумма элементов результата равна сумме всех элементов входных
-- списков:
--
-- sum (zipWithSum xs ys) == sum xs + sum ys
prop_zipWithSum_sum :: [Int] -> [Int] -> Bool
prop_zipWithSum_sum xs ys = sum (zipWithSum xs ys) == sum xs + sum ys

main :: IO ()
main = do
  quickCheck prop_isCongruent_diffDivisible
  quickCheck prop_isCongruent_symmetry
  quickCheck prop_isCongruent_equalAlwaysCongruent
  quickCheck prop_zipWithSum_length
  quickCheck prop_zipWithSum_emptyList
  quickCheck prop_zipWithSum_sum