aboutsummaryrefslogtreecommitdiff
path: root/README.org
blob: 71ad41b6372daf425c56393805522d39b650d55e (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
53
54
55
56
57
#+title: Testing in Haskell
#+date: 2024H2

* Task
:PROPERTIES:
:CUSTOM_ID: task
:END:
Create a project in =stack=.  In the =stack= project, there is a =tests=
directory, which contains the file =Spec.hs=, where you can also write
~main~ to display the test results.  You need to test two functions:
1. ~isCongruent :: Int -> Int -> Int -> Bool~
2. ~zipWithSum :: [Int] -> [Int] -> [Int]~

** ~isCongruent :: Int -> Int -> Int -> Bool Int -> Bool~
The modulo equality check function ~isCongruent :: Int -> Int -> Int ->
Bool Int -> Bool~ checks whether two numbers are congruent modulo a
third number.

Using ~QuickCheck~, verify the following properties:
1. If two numbers are congruent modulo, then their difference is
   divisible by the modulus:
   - ~isCongruent a b m == (modulus (a - b) m == 0)~.
2. Equality modulo is symmetric:
   - ~isCongruent a b m == isCongruent b a m~.
3. If one number is equal to another, then they are equal modulo any
   value:
   - if a = b, then ~isCongruent a b m == True~.

** ~zipWithSum :: [Int] -> [Int] -> [Int]~
The function ~zipWithSum :: [Int] -> [Int] -> [Int]~ takes two lists of
integers and returns a new list where each element is the sum of the
corresponding elements of the two lists. If the list lengths differ,
the remaining elements of the longer list should be added to the end
of the result.

 Using ~QuickCheck~, verify the following properties:
1. The length of the result is equal to the maximum length of the
   input lists:
   - ~length (zipWithSum xs ys) == max (length xs) (length ys)~.
2. If one of the lists is empty, then the result is the same as the
   non‑empty list:
   - if ~xs~ is empty, then ~zipWithSum [] ys == ys~.
3. The sum of the elements of the result is equal to the sum of all
   elements of the input lists:
   - ~sum (zipWithSum xs ys) == sum xs + sum ys~.

* Documentation
:PROPERTIES:
:CUSTOM_ID: documentation
:END:
The exported report can be found at [[https://git.michalec.dev/files/uni/term-05/func-prog/lab-04/report.pdf][this link]].

* Unlicense
:PROPERTIES:
:CUSTOM_ID: unlicense
:END:
#+include: UNLICENSE verse