diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/Spec.hs | 52 |
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 @@ | |||
| 1 | import Lib (isCongruent, zipWithSum) | ||
| 2 | import Test.QuickCheck | ||
| 3 | |||
| 4 | -- Если два числа равны по модулю, то их разность делится на модуль: | ||
| 5 | -- | ||
| 6 | -- isCongruent a b m == (modulus (a - b) m == 0) | ||
| 7 | prop_isCongruent_diffDivisible :: Int -> Int -> Int -> Property | ||
| 8 | prop_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 | ||
| 14 | prop_isCongruent_symmetry :: Int -> Int -> Int -> Property | ||
| 15 | prop_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 | ||
| 21 | prop_isCongruent_equalAlwaysCongruent :: Int -> Int -> Property | ||
| 22 | prop_isCongruent_equalAlwaysCongruent a m = m /= 0 ==> isCongruent a a m == True | ||
| 23 | |||
| 24 | -- Длины результата равна максимальной длине входных списков: | ||
| 25 | -- | ||
| 26 | -- length (zipWithSum xs ys) == max (length xs) (length ys) | ||
| 27 | prop_zipWithSum_length :: [Int] -> [Int] -> Bool | ||
| 28 | prop_zipWithSum_length xs ys = | ||
| 29 | length (zipWithSum xs ys) == max (length xs) (length ys) | ||
| 30 | |||
| 31 | -- Если один из списков пустой, то результат совпадает с непустым | ||
| 32 | -- списком: | ||
| 33 | -- | ||
| 34 | -- если xs пустой, то zipWithSum [] ys == ys | ||
| 35 | prop_zipWithSum_emptyList :: [Int] -> Bool | ||
| 36 | prop_zipWithSum_emptyList xs = zipWithSum [] xs == xs && zipWithSum xs [] == xs | ||
| 37 | |||
| 38 | -- Сумма элементов результата равна сумме всех элементов входных | ||
| 39 | -- списков: | ||
| 40 | -- | ||
| 41 | -- sum (zipWithSum xs ys) == sum xs + sum ys | ||
| 42 | prop_zipWithSum_sum :: [Int] -> [Int] -> Bool | ||
| 43 | prop_zipWithSum_sum xs ys = sum (zipWithSum xs ys) == sum xs + sum ys | ||
| 44 | |||
| 45 | main :: IO () | ||
| 46 | main = 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 | ||
