aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-11-08 04:29:28 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-11-08 04:29:28 +0000
commit44e725659b941682c621a2fd9309ab4acc8ab199 (patch)
treed6f8ff36b790a0b1b77688d488a88859d20a9ec1 /test
downloadlab-04-44e725659b941682c621a2fd9309ab4acc8ab199.tar.gz
publishHEADmaster
Diffstat (limited to 'test')
-rw-r--r--test/Spec.hs52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/Spec.hs b/test/Spec.hs
new file mode 100644
index 0000000..eeccba0
--- /dev/null
+++ b/test/Spec.hs
@@ -0,0 +1,52 @@
1import Lib (isCongruent, zipWithSum)
2import Test.QuickCheck
3
4-- Если два числа равны по модулю, то их разность делится на модуль:
5--
6-- isCongruent a b m == (modulus (a - b) m == 0)
7prop_isCongruent_diffDivisible :: Int -> Int -> Int -> Property
8prop_isCongruent_diffDivisible a b m =
9 m /= 0 ==> isCongruent a b m == ((a - b) `mod` m == 0)
10
11-- Равенство по модулю является симметричным:
12--
13-- isCongruent a b m == isCongruent b a m
14prop_isCongruent_symmetry :: Int -> Int -> Int -> Property
15prop_isCongruent_symmetry a b m =
16 m /= 0 ==> isCongruent a b m == isCongruent b a m
17
18-- Если одно число равно другому, то они равны по любому модулю:
19--
20-- если a == b, то isCongruent a b m == True
21prop_isCongruent_equalAlwaysCongruent :: Int -> Int -> Property
22prop_isCongruent_equalAlwaysCongruent a m = m /= 0 ==> isCongruent a a m == True
23
24-- Длины результата равна максимальной длине входных списков:
25--
26-- length (zipWithSum xs ys) == max (length xs) (length ys)
27prop_zipWithSum_length :: [Int] -> [Int] -> Bool
28prop_zipWithSum_length xs ys =
29 length (zipWithSum xs ys) == max (length xs) (length ys)
30
31-- Если один из списков пустой, то результат совпадает с непустым
32-- списком:
33--
34-- если xs пустой, то zipWithSum [] ys == ys
35prop_zipWithSum_emptyList :: [Int] -> Bool
36prop_zipWithSum_emptyList xs = zipWithSum [] xs == xs && zipWithSum xs [] == xs
37
38-- Сумма элементов результата равна сумме всех элементов входных
39-- списков:
40--
41-- sum (zipWithSum xs ys) == sum xs + sum ys
42prop_zipWithSum_sum :: [Int] -> [Int] -> Bool
43prop_zipWithSum_sum xs ys = sum (zipWithSum xs ys) == sum xs + sum ys
44
45main :: IO ()
46main = do
47 quickCheck prop_isCongruent_diffDivisible
48 quickCheck prop_isCongruent_symmetry
49 quickCheck prop_isCongruent_equalAlwaysCongruent
50 quickCheck prop_zipWithSum_length
51 quickCheck prop_zipWithSum_emptyList
52 quickCheck prop_zipWithSum_sum