diff options
| author | 2026-11-08 04:29:28 +0000 | |
|---|---|---|
| committer | 2026-11-08 04:29:28 +0000 | |
| commit | 44e725659b941682c621a2fd9309ab4acc8ab199 (patch) | |
| tree | d6f8ff36b790a0b1b77688d488a88859d20a9ec1 /README.org | |
| download | lab-04-master.tar.gz | |
Diffstat (limited to 'README.org')
| -rw-r--r-- | README.org | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/README.org b/README.org new file mode 100644 index 0000000..71ad41b --- /dev/null +++ b/README.org | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | #+title: Testing in Haskell | ||
| 2 | #+date: 2024H2 | ||
| 3 | |||
| 4 | * Task | ||
| 5 | :PROPERTIES: | ||
| 6 | :CUSTOM_ID: task | ||
| 7 | :END: | ||
| 8 | Create a project in =stack=. In the =stack= project, there is a =tests= | ||
| 9 | directory, which contains the file =Spec.hs=, where you can also write | ||
| 10 | ~main~ to display the test results. You need to test two functions: | ||
| 11 | 1. ~isCongruent :: Int -> Int -> Int -> Bool~ | ||
| 12 | 2. ~zipWithSum :: [Int] -> [Int] -> [Int]~ | ||
| 13 | |||
| 14 | ** ~isCongruent :: Int -> Int -> Int -> Bool Int -> Bool~ | ||
| 15 | The modulo equality check function ~isCongruent :: Int -> Int -> Int -> | ||
| 16 | Bool Int -> Bool~ checks whether two numbers are congruent modulo a | ||
| 17 | third number. | ||
| 18 | |||
| 19 | Using ~QuickCheck~, verify the following properties: | ||
| 20 | 1. If two numbers are congruent modulo, then their difference is | ||
| 21 | divisible by the modulus: | ||
| 22 | - ~isCongruent a b m == (modulus (a - b) m == 0)~. | ||
| 23 | 2. Equality modulo is symmetric: | ||
| 24 | - ~isCongruent a b m == isCongruent b a m~. | ||
| 25 | 3. If one number is equal to another, then they are equal modulo any | ||
| 26 | value: | ||
| 27 | - if a = b, then ~isCongruent a b m == True~. | ||
| 28 | |||
| 29 | ** ~zipWithSum :: [Int] -> [Int] -> [Int]~ | ||
| 30 | The function ~zipWithSum :: [Int] -> [Int] -> [Int]~ takes two lists of | ||
| 31 | integers and returns a new list where each element is the sum of the | ||
| 32 | corresponding elements of the two lists. If the list lengths differ, | ||
| 33 | the remaining elements of the longer list should be added to the end | ||
| 34 | of the result. | ||
| 35 | |||
| 36 | Using ~QuickCheck~, verify the following properties: | ||
| 37 | 1. The length of the result is equal to the maximum length of the | ||
| 38 | input lists: | ||
| 39 | - ~length (zipWithSum xs ys) == max (length xs) (length ys)~. | ||
| 40 | 2. If one of the lists is empty, then the result is the same as the | ||
| 41 | non‑empty list: | ||
| 42 | - if ~xs~ is empty, then ~zipWithSum [] ys == ys~. | ||
| 43 | 3. The sum of the elements of the result is equal to the sum of all | ||
| 44 | elements of the input lists: | ||
| 45 | - ~sum (zipWithSum xs ys) == sum xs + sum ys~. | ||
| 46 | |||
| 47 | * Documentation | ||
| 48 | :PROPERTIES: | ||
| 49 | :CUSTOM_ID: documentation | ||
| 50 | :END: | ||
| 51 | The exported report can be found at [[https://git.michalec.dev/files/uni/term-05/func-prog/lab-04/report.pdf][this link]]. | ||
| 52 | |||
| 53 | * Unlicense | ||
| 54 | :PROPERTIES: | ||
| 55 | :CUSTOM_ID: unlicense | ||
| 56 | :END: | ||
| 57 | #+include: UNLICENSE verse | ||
