-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHW01Tests.hs
77 lines (58 loc) · 2.15 KB
/
HW01Tests.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
73
74
75
76
77
-- CIS 194, Spring 2015
--
-- Test cases for HW 01
module HW01Tests where
import HW01
import Testing
-- Exercise 1 -----------------------------------------
testLastDigit :: (Integer, Integer) -> Bool
testLastDigit (n, d) = lastDigit n == d
testDropLastDigit :: (Integer, Integer) -> Bool
testDropLastDigit (n, d) = dropLastDigit n == d
ex1Tests :: [Test]
ex1Tests = [ Test "lastDigit test" testLastDigit
[(123, 3), (1234, 4), (5, 5), (10, 0), (0, 0)]
, Test "dropLastDigit test" testDropLastDigit
[(123, 12), (1234, 123), (5, 0), (10, 1), (0,0)]
]
-- Exercise 2 -----------------------------------------
testRevDigits :: (Integer, [Integer]) -> Bool
testRevDigits (n, d) = toRevDigits n == d
ex2Tests :: [Test]
ex2Tests = [ Test "toRevDigits test" testRevDigits
[(1234, [4,3,2,1]), ((-17), []), (0, [])]
]
-- Exercise 3 -----------------------------------------
testDoubleEveryOther :: ([Integer], [Integer]) -> Bool
testDoubleEveryOther (n, d) = doubleEveryOther n == d
ex3Tests :: [Test]
ex3Tests = [ Test "doubleEveryOther test" testDoubleEveryOther
[([4,9,5,5], [4,18,5,10]), ([0,(-1)], [0,(-2)]), ([1], [1])]
]
-- Exercise 4 -----------------------------------------
testSumDigits :: ([Integer], Integer) -> Bool
testSumDigits (n, d) = sumDigits n == d
ex4Tests :: [Test]
ex4Tests = [ Test "sumDigits test" testSumDigits
[([10, 5, 18, 4], 19), ([], 0), ([3], 3), ([18], 9)]
]
-- Exercise 5 -----------------------------------------
testLuhn :: (Integer, Bool) -> Bool
testLuhn (n, d) = luhn n == d
ex5Tests :: [Test]
ex5Tests = [ Test "luhn test" testLuhn
[(5594589764218858, True), (1234567898765432, False)]
]
-- Exercise 6 -----------------------------------------
ex6Tests :: [Test]
ex6Tests = []
-- hanoi 2 "a" "b" "c" == [("a","c"), ("a","b"), ("c","b")]
-- All Tests ------------------------------------------
allTests :: [Test]
allTests = concat [ ex1Tests
, ex2Tests
, ex3Tests
, ex4Tests
, ex5Tests
, ex6Tests
]