-
Notifications
You must be signed in to change notification settings - Fork 10
/
3.hs
72 lines (61 loc) · 2.05 KB
/
3.hs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- % cabal install hspec
-- % runghc <this_file>
import Small
main :: IO ()
main = hspec $ do
describe "my_lt" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 0
==> my_lt m n == (m < n)
describe "my_lteq" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 0
==> my_lteq m n == (m <= n)
describe "my_even" $
prop "behaves as model" $ \(Small n) -> n >= 0
==> my_even n == even n
describe "my_divide" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 1
==> my_divide m n == m `div` n
describe "my_gt" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 0
==> my_gt m n == (m > n)
describe "my_gteq" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 0
==> my_gteq m n == (m >= n)
describe "my_odd" $
prop "behaves as model" $ \(Small n) -> n >= 0
==> my_odd n == odd n
describe "my_remainder" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 1
==> my_remainder m n == m `mod` n
describe "my_divide_iter" $
prop "behaves as model" $ \(Small m) (Small n) -> m >= 0 && n >= 1
==> my_divide_iter m n == m `div` n
my_lt :: Integer -> Integer -> Bool
my_lt _ 0 = False
my_lt 0 _ = True
my_lt m n = my_lt (m - 1) (n - 1)
my_lteq :: Integer -> Integer -> Bool
my_lteq 0 _ = True
my_lteq _ 0 = False
my_lteq m n = my_lteq (m - 1) (n - 1)
my_even :: Integer -> Bool
my_even 0 = True
my_even 1 = False
my_even n = my_even (n - 2)
my_divide :: Integer -> Integer -> Integer
my_divide m n
| m < n = 0
| otherwise = my_divide (m - n) n + 1
my_gt :: Integer -> Integer -> Bool
my_gt = undefined
my_gteq :: Integer -> Integer -> Bool
my_gteq = undefined
my_odd :: Integer -> Bool
my_odd = undefined
my_remainder :: Integer -> Integer -> Integer
my_remainder = undefined
my_divide_iter :: Integer -> Integer -> Integer
my_divide_iter x y = iter x y undefined
where
iter :: Integer -> Integer -> Integer -> Integer
iter = undefined