From 44e725659b941682c621a2fd9309ab4acc8ab199 Mon Sep 17 00:00:00 2001 From: Martin Michalec Date: Sun, 8 Nov 2026 07:29:28 +0300 Subject: publish --- README.org | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 README.org (limited to 'README.org') diff --git a/README.org b/README.org new file mode 100644 index 0000000..71ad41b --- /dev/null +++ b/README.org @@ -0,0 +1,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 -- cgit v1.3.1